Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DNumber] Add rawValue attribute to hold the original value #833

Merged
merged 2 commits into from May 15, 2022

Conversation

TomasVotruba
Copy link
Contributor

Mirror to #832

@TomasVotruba
Copy link
Contributor Author

This PR will help using native node properties, instead of token + attribute hacking:
rectorphp/rector-src#2302

@TomasVotruba TomasVotruba changed the title [DNumber] Add 3rd argument raw value to keep original value [DNumber] Add rawValue attribute to hold the original value May 12, 2022
Comment on lines +27 to +37
/**
* @param mixed[] $attributes
*/
public static function fromString(string $str, array $attributes = []): DNumber
{
$attributes['rawValue'] = $str;
$float = self::parse($str);

return new DNumber($float, $attributes);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should mirror the LNumber::fromString() https://github.com/nikic/PHP-Parser/pull/832/files#diff-dcef01e803010221926e1c1f1d388bd86cd219dc843253abf177cca48fb57ba1

We could add this to grammar itself, but it would require either custom method in AbstractParser or some grammar coding. That would be both harder to maintain and inconsistent with LNumber.

@TomasVotruba
Copy link
Contributor Author

The value is now in "rawValue" attribute.

Ready for review ✔️

@nikic nikic merged commit 3bf0082 into nikic:master May 15, 2022
@TomasVotruba TomasVotruba deleted the tv-dnumber-parse branch May 15, 2022 17:04
@TomasVotruba
Copy link
Contributor Author

👏

@TomasVotruba
Copy link
Contributor Author

With this feature, tokens are now finally removed from @rectorphp 🥳
https://github.com/rectorphp/rector-src/pull/2321/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants