-
-
Notifications
You must be signed in to change notification settings - Fork 30
Replace substr in getCode() to cover more cases. #61
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
Conversation
The current replacer does not cover all cases to remove declare statements regarding 'strict_types' definitions. Currently not covered: * If there is more than one line break before the declare statement * If there are arbitrary spaces within the declare statement * If there is a comment before the declare statement To not build the whole statemachine by ourself I decided to use a regex to tackle those problems. As this will in most cases only be ran if the boostrap needs to be regenerated we should be safe with the implied performance hit regarding the usage of regex here. Rundown on the Regex parts: * `^` - Match the beginning of the file only * `(<\?php)?` - Match starting PHP Tags (if existent) * `([\s]*/\*\*?.*?\*/[\s]*)?` - Match file comments (if existent) * `[\s]*` - Match arbitrary number of spaces * `(declare[\s]*\([\s]*strict_types[\s]*=[\s]*1[\s]*\);)?` - Match strict definition (if existent) This should handle the whole pretty cleanup more gracefully regarding external/vendored codebases which may not apply to some predefined CodingStandard.
|
Not throughly tested as its broken atm. and it removes too much |
Because of the multiline modifier we matched everything within the whole file and not just from beginning. This resulted in removing all comments and whitespaces -- whoops!
|
Thanks! Please could you also add a test case that oreviously failed, but now passes? |
|
Tests were added and I also found a missing spacing part in the regex. |
Those should not be checked for styling though!
This should fix PHP Parser <3.0 errors.
|
Hey there, I don't want to rush you, but could you do a review and merge this upstream so I can use this library directly instead of patching my composer.json with my patch repository/branch? |
|
Thanks. 👍 |
|
Just tagged 3.2.0. |
The current replacer does not cover all cases to remove declare statements regarding 'strict_types' definitions.
Currently not covered:
To not build the whole statemachine by ourself I decided to use a regex to tackle those problems. As this will in most cases only be ran if the boostrap needs to be regenerated we should be safe with the implied performance hit regarding the usage of regex here.
Rundown on the Regex parts:
^- Match the beginning of the file only(<\?php)?- Match starting PHP Tags (if existent)([\s]*/\*\*?.*?\*/[\s]*)?- Match file comments (if existent)[\s]*- Match arbitrary number of spaces(declare[\s]*\([\s]*strict_types[\s]*=[\s]*1[\s]*\);)?- Match strict definition (if existent)This should handle the whole pretty cleanup more gracefully regarding external/vendored codebases which may not apply to some predefined CodingStandard.