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

Undefined index error with pre-commit hook using husky on PHP 7.4 #3163

Closed

Conversation

ivuorinen
Copy link
Contributor

For some unknown reason, doing git pre-commit hook with husky and PHP 7.4, FileList method current tries to access undefined array index and throws RuntimeException.

✖ vendor/bin/phpcs --standard=phpcs.xml web/app/ config/ found some errors. Please fix them and try committing again.
.....
Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Undefined index:  in vendor/squizlabs/php_codesniffer/src/Files/FileList.php on line 187 in vendor/squizlabs/php_codesniffer/src/Runner.php:606
Stack trace:
#0 vendor/squizlabs/php_codesniffer/src/Files/FileList.php(187): PHP_CodeSniffer\Runner→handleErrors(8, 'Undefined index...', '/Users/ivuorine...', 187, Array)
#1 vendor/squizlabs/php_codesniffer/src/Runner.php(487): PHP_CodeSniffer\Files\FileList→current()
#2 vendor/squizlabs/php_codesniffer/src/Runner.php(114): PHP_CodeSniffer\Runner→run()
#3 vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner→runPHPCS()
#4 {main}
thrown in vendor/squizlabs/php_codesniffer/src/Runner.php on line 606
.......�[33mW�[0m......�[33mW�[0m...�[33mW�[0m.�[33mW�[0m....�[33mW�[0m...�[31mE�[0m. 36 / 36 (100%)

After adding the isset($this->files[$path]) === false check, linting works as expected.

✖ vendor/bin/phpcs --standard=phpcs.xml web/app/ config/ found some errors. Please fix them and try committing again.
�[33mW�[0m...............�[33mW�[0m.......�[33mW�[0m....�[33mW�[0m.�[31mE�[0m�[33mW�[0m... 36 / 36 (100%)

For some unknown reason, doing git precommit hook with husky and
PHP 7.4, FileList method `current` tries to access undefined array
index and throws RuntimeException.

After adding the `isset($this->files[$path]) === false` check,
linting works as expected.
@ivuorinen
Copy link
Contributor Author

@gsherwood Sorry to ping you, but could you check this out?

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Dec 11, 2020
@gsherwood gsherwood added this to the 3.6.0 milestone Dec 11, 2020
@gsherwood gsherwood changed the title Files/FileList::current() - Check files array key Undefined index error with pre-commit hook using husky on PHP 7.4 Jan 13, 2021
gsherwood added a commit that referenced this pull request Jan 13, 2021
@gsherwood gsherwood closed this Jan 13, 2021
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Jan 13, 2021
@gsherwood
Copy link
Member

I couldn't figure out how to replicate this, but the isset() statement is a good alternative to the null comparison anyway, and if that gets this working then all the better. I ended up removing the null comparison because it was doing the same thing anyway. The new commit is here: 072042a

Thanks for finding and fixing this.

@ivuorinen ivuorinen deleted the fix-undefined-index-exception branch January 14, 2021 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging this pull request may close these issues.

None yet

2 participants