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

Squiz/NonExecutableCode: fix undefined index during live coding reviews #1706

Merged

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Oct 14, 2017

Came across this error when running fixer conflict checks for the various standards. (See #1645 (comment) )
First fix in a series to fix the issues found.

Error encountered: Undefined index: scope_closer in phpcs/src/Standards/Squiz/Sniffs/PHP/NonExecutableCodeSniff.php on line 238

Error occurs when an unfinished function or OO structure is encountered.

While looking at the code, I saw three more minor improvements which I have included in this PR:

  • Account for modern PHP OO structures.
    The sniff is designed to skip over declarations, but only accounted for functions, classes and interfaces.
    This has been updated to include closures, traits and anonymous classes.
  • Add the semi-colon to the ignore list for reporting.
    In this context a 'lone' semi-colon is most often encountered at the end of a closure or anonymous class, so this might as well be skipped over.
  • The sniff can thrown two or more errors on the same line when several "exit" commands have been found above the line.
    I've adjusted the error message to also report on the line where the "exit" command was encountered to make it easier to fix/debug these type of errors.

Includes unit tests.

To reproduce/test: take the updated unit test file and just run the original sniff over it.

Came across this error when running fixer conflict checks for the various standards.

Error encountered: `Undefined index: scope_closer in phpcs/src/Standards/Squiz/Sniffs/PHP/NonExecutableCodeSniff.php on line 238`

Error occurred when an unfinished function or OO structure is encountered.

While looking at the code, I saw three more minor improvements which I have included in this PR:
* Account for modern PHP OO structures.
    The sniff is designed to skip over declarations, but only accounted for functions, classes and interfaces.
    This has been updated to include closures, traits and anonymous classes.
* Add the semi-colon to the ignore list for reporting.
    In this context a 'lone' semi-colon is most often encountered at the end of a closure or anonymous class, so this might as well be skipped over.
* The sniff can thrown two or more errors on the same line when several "exit" commands have been found above the line.
    I've adjusted the error message to also report on the line where the "exit" command was encountered to make it easier to fix/debug these type of errors.

Includes unit tests.

To reproduce/test: take the updated unit test file and just run the original sniff over it.
@jrfnl jrfnl force-pushed the feature/fix-squiz-non-executable-code branch from 150f8fb to b9ade19 Compare November 22, 2017 05:39
@jrfnl
Copy link
Contributor Author

jrfnl commented Nov 22, 2017

Rebased for merge conflicts & updated code style...

@gsherwood gsherwood added this to the 3.2.0 milestone Nov 28, 2017
@gsherwood gsherwood merged commit b9ade19 into squizlabs:master Nov 28, 2017
@jrfnl jrfnl deleted the feature/fix-squiz-non-executable-code branch November 28, 2017 23:16
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.

2 participants