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 PSR12.Functions.ReturnTypeDeclaration #161

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=PSR12 --ignore="*/build/*,*/vendor/*" --basepath=. --extensions=inc --suffix=.conflictcheck

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

FFFFFFFFFEFFFFFF..EFFFFFE..FEFFFFFFFFFFFFFFFFFFFFFFFEF..FFF.  60 / 444 (14%)
.FFFF.FF..F...F..FFFFFF.F.FFFFFFFFEFFFFFFFFFFFFFFFFFFFFPHP Fatal error:  Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Undefined array key -1 in .../src/Standards/PSR12/Sniffs/Functions/ReturnTypeDeclarationSniff.php on line 89 in .../src/Runner.php:608
Stack trace:
#0 .../src/Standards/PSR12/Sniffs/Functions/ReturnTypeDeclarationSniff.php(89): PHP_CodeSniffer\Runner->handleErrors()
#1 .../src/Files/File.php(518): PHP_CodeSniffer\Standards\PSR12\Sniffs\Functions\ReturnTypeDeclarationSniff->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

This only happens when a file containing a git merge conflict is being scanned. Files contain git merge conflicts should (and will) be excluded from the fixer conflict check as the tokenizer will return an invalid token stream for those no matter what.

This was noted as a "caveat" already in issue #152.

@jrfnl jrfnl closed this Dec 13, 2023
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