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

NormalizedArrays/CommaAfterLast: improve fixer for flexible heredoc/nowdoc #144

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Oct 30, 2022

When comma's are enforced after the last entry of a (multi-line) array, the fixer would previously always add a new line between the heredoc/nowdoc closer and the comma to prevent parse errors in PHP < 7.3.

However, the "closer" token for a flexible heredoc/nowdoc will include the indentation whitespace. This allows us to distinguish between "old-style" heredoc/nowdocs and PHP 7.3+ heredoc/nowdocs.

This commit updates the fixer to check for this indentation whitespace and if found, will no longer add the new line.

Includes tests in a separate file as these tests can only run on PHP 7.3+ (as the token stream of a file containing flexible heredoc/nowdocs in PHP < 7.3 will be garbage after the first heredoc/nowdoc).

…owdoc

When comma's are enforced after the last entry of a (multi-line) array, the fixer would previously always add a new line between the heredoc/nowdoc closer and the comma to prevent parse errors in PHP < 7.3.

However, the "closer" token for a flexible heredoc/nowdoc will include the indentation whitespace. This allows us to distinguish between "old-style" heredoc/nowdocs and PHP 7.3+ heredoc/nowdocs.

This commit updates the fixer to check for this indentation whitespace and if found, will no longer add the new line.

Includes tests in a separate file as these tests can only run on PHP 7.3+ (as the token stream of a file containing flexible heredoc/nowdocs in PHP < 7.3 will be garbage after the first heredoc/nowdoc).
@jrfnl jrfnl added this to the 1.0.0-alpha4 milestone Oct 30, 2022
@jrfnl jrfnl merged commit d418624 into develop Oct 30, 2022
@jrfnl jrfnl deleted the normalizedarrays/commaafterlast-improve-fixer-heredoc-as-last-item branch October 30, 2022 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant