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

PEAR/FunctionDeclaration: bug fix x 2 - prevent fixer creating a parse error + prevent fixer conflict #52

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Nov 9, 2023

Description

Recreation of upstream PR squizlabs/PHP_CodeSniffer#3739:

PEAR/FunctionDeclaration: bug fix - prevent fixer from creating a parse error

Issue as described in squizlabs/PHP_CodeSniffer#3736.

The fixer would try to remove superfluous whitespace remaining after the move of the opening brace to the previous line, but did not take into account that there may not be any whitespace to remove, i.e. that the $opener +1 token could be the same as the $next token.

Fixed now.

Includes unit test.

Fixes squizlabs/PHP_CodeSniffer#3736

PEAR/FunctionDeclaration: prevent fixer conflict

This commit was originally pulled as part of PR squizlabs/PHP_CodeSniffer#3661.

If a return type declaration was not confined to one line, the sniff could have a fixer conflict with itself.
The fixer would also potentially remove a close curly on the same line, causing parse errors.

Fixed now. The diff will be most straight forward to review while ignoring whitespace changes.

Includes unit tests.

Suggested changelog entry

  • PEAR/FunctionDeclaration: bug fix - prevent fixer from creating a parse error
  • PEAR/FunctionDeclaration: prevent fixer conflict

…se error

Issue as described in 3736.

The fixer would try to remove superfluous whitespace remaining after the move of the opening brace to the previous line, but did not take into account that there may not be any whitespace to removed, i.e. that the `$opener +1` token could be the same as the `$next` token.

Fixed now.

Includes unit test.

Fixes 3736
If a return type declaration was not confined to one line, the sniff could have a fixer conflict with itself.
The fixer would also potentially remove a close curly on the same line, causing parse errors.

Fixed now. The diff will be most straight forward to review while ignoring whitespace changes.

Includes unit tests.
@jrfnl jrfnl force-pushed the feature/3736-pear-functiondeclaration-fix-fixer-creating-parse-error branch from 661224e to dcc257f Compare December 5, 2023 00:25
@jrfnl jrfnl merged commit 68e7d9e into master Dec 5, 2023
65 checks passed
@jrfnl jrfnl deleted the feature/3736-pear-functiondeclaration-fix-fixer-creating-parse-error branch December 5, 2023 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant