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

Compactor\Php: add support for PHP 8.0+ attributes + small other fix #568

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Oct 10, 2021

Compactor\Php: add tests with trailing comments

Compactor\Php: fix stray whitespace at start of line after removal trailing comment

The tokens for comments in # and // format include the new line character at the end of the comment in PHP < 8.0.
This would lead to the "is this leading whitespace at the start of a line" check, not trimming leading whitespace on the line after a (trimmed) comment.

Fixed now.

Compactor\Php: add tests with PHP 8.0 attributes

Compactor\Php: add support for PHP 8.0+ attributes

Up to now, when a Phar was being created using PHP < 8.0 with the PHP compactor enabled, PHP 8.0+ attributes would be incorrectly removed as if they were comments.

This has now been fixed.

Both the solution implemented, as well as the unit tests, are largely inspired by the solution for handling attributes when code is being tokenized on PHP < 8.0, as implemented in PHP_CodeSniffer in squizlabs/PHP_CodeSniffer#3203 and squizlabs/PHP_CodeSniffer#3299. Props to @alekitto.

Fixes #567

jrfnl and others added 4 commits October 10, 2021 20:57
…ailing comment

The tokens for comments in `#` and `//` format include the new line character at the end of the comment in PHP < 8.0.
This would lead to the "is this leading whitespace at the start of a line" check, not trimming leading whitespace on the line after a (trimmed) comment.

Fixed now.
Up to now, when a Phar was being created using PHP < 8.0 with the PHP compactor enabled, PHP 8.0+ attributes would be incorrectly removed as if they were comments.

This has now been fixed.

Both the solution implemented, as well as the unit tests, are largely inspired by the solution for handling attributes when code is being tokenized on PHP < 8.0, as implemented in `PHP_CodeSniffer` in squizlabs/PHP_CodeSniffer#3203 and squizlabs/PHP_CodeSniffer#3299. Props to alekitto.

Fixes 567

Co-authored-by: Alessandro Chitolina <alekitto@gmail.com>
@theofidry
Copy link
Member

👌 Thanks a lot for the thorough patches @jrfnl!

@jrfnl jrfnl deleted the feature/567-fix-php-compactor-stripping-attributes branch October 18, 2021 15:42
@jrfnl
Copy link
Contributor Author

jrfnl commented Oct 18, 2021

Glad I could help. 👍🏻

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.

PHP Compactor removes attributes when Phar is being generated on PHP < 8.0
2 participants