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

Fix PHP Notice in Squiz.PHP.NonExecutableCode #162

Conversation

fredden
Copy link
Member

@fredden fredden commented Dec 13, 2023

Description

(After applying the changes in #160 locally...)
While looking into #152, I ran the following command:
phpcbf -p . --standard=Squiz --ignore="*/build/*,*/vendor/*" --basepath=. --extensions=inc --suffix=.conflictcheck

Instead of a useful report, I got a PHP Fatal error:

EFFFFFFEFEEEEFFEFFEFFEFEEFFEEEFFEFFFFFFFFEFFFFFFFFPHP Fatal error:  Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Undefined array key "scope_condition" in .../src/Standards/Squiz/Sniffs/PHP/NonExecutableCodeSniff.php on line 116 in .../src/Runner.php:608
Stack trace:
#0 .../src/Standards/Squiz/Sniffs/PHP/NonExecutableCodeSniff.php(116): PHP_CodeSniffer\Runner->handleErrors()
#1 .../src/Files/File.php(518): PHP_CodeSniffer\Standards\Squiz\Sniffs\PHP\NonExecutableCodeSniff->process()
#2 .../src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
#3 .../src/Fixer.php(174): PHP_CodeSniffer\Files\LocalFile->process()
#4 .../src/Reports/Cbf.php(52): PHP_CodeSniffer\Fixer->fixFile()
#5 .../src/Reporter.php(285): PHP_CodeSniffer\Reports\Cbf->generateFileReport()
#6 .../src/Runner.php(691): PHP_CodeSniffer\Reporter->cacheFileReport()
#7 .../src/Runner.php(438): PHP_CodeSniffer\Runner->processFile()
#8 .../src/Runner.php(204): PHP_CodeSniffer\Runner->run()
#9 .../bin/phpcbf(18): PHP_CodeSniffer\Runner->runPHPCBF()
#10 {main}
  thrown in .../src/Runner.php on line 608

This pull request fixes this error, allowing the suggested command to produce a report.
I'm not adding any specific tests for this, as the integration test that will eventually be added as part of #152 will cover this case.

Suggested changelog entry

Related issues/external references

Related to #152

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

PR checklist

  • I have checked there is no other PR open for the same change.
  • I have read the Contribution Guidelines.
  • I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
  • I have added tests to cover my changes.
  • I have verified that the code complies with the projects coding standards.
  • [Required for new sniffs] I have added XML documentation for the sniff.

@fredden fredden marked this pull request as ready for review December 13, 2023 13:41
@jrfnl
Copy link
Member

jrfnl commented Dec 13, 2023

Closing as not the correct fix - see #149 which I'd opened about this already.

@jrfnl jrfnl closed this Dec 13, 2023
@fredden fredden deleted the php-notice/Squiz.PHP.NonExecutableCode branch December 13, 2023 16:46
@fredden
Copy link
Member Author

fredden commented Dec 13, 2023

Thanks. I did look through the open pull requests, but didn't realise the connection / overlap with #149.

@fredden fredden restored the php-notice/Squiz.PHP.NonExecutableCode branch December 13, 2023 17:13
@fredden
Copy link
Member Author

fredden commented Dec 13, 2023

Thanks. I did look through the open pull requests, but didn't realise the connection / overlap with #149.

I've now realised that #149 is an issue, not a pull request. Closing this pull request as a duplicate of an issue makes less sense to me. Can we get this merged in (as it blocks #152) while we wait for a fix for #149 (which seems more broadly scoped than this)?

@fredden fredden reopened this Dec 13, 2023
@jrfnl
Copy link
Member

jrfnl commented Dec 13, 2023

Thanks. I did look through the open pull requests, but didn't realise the connection / overlap with #149.

I've now realised that #149 is an issue, not a pull request. Closing this pull request as a duplicate of an issue makes less sense to me. Can we get this merged in (as it blocks #152) while we wait for a fix for #149 (which seems more broadly scoped than this)?

Merging this would hide the problem, instead fixing it, so that is not a solution, but a problem multiplying.

IMO this issue is not a blocker for #152 when checking individual conflicts. You would only run into it when trying to run the complete check, which is not the ask.

All the same, if you want to do that, you can have this as a commit locally in a WIP branch (like I have as well), but I do not consider it a valid fix as this is a situation which should never be able to happen and adding defensive coding for a situation which shouldn't be able to exist is not the way to go.

@fredden
Copy link
Member Author

fredden commented Dec 14, 2023

Merging this would hide the problem, instead fixing it, so that is not a solution, but a problem multiplying.

I agree that #149 is a valid bug. I agree that this pull request hides one of the symptoms of that bug. I agree that this pull request does not fix (and does not attempt to fix) #149. It seems that we disagree on whether or not this pull request adds value to the project in its current form. I'll close this off now to reduce the noise / respect your decision.

@fredden fredden closed this Dec 14, 2023
@fredden fredden deleted the php-notice/Squiz.PHP.NonExecutableCode branch December 14, 2023 15:48
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.

2 participants