-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
PHP 7.4 closures with array_filter breaks sniffs #839
Comments
@raalderink Do you really mean |
@kukulich Yes, the fixer throws this on that code: Stack trace:
#0 /.../vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/NullableTypeForNullDefaultValueSniff.php(40): PHP_CodeSniffer\Runner->handleErrors(8, 'Undefined index...', '/...', 40, Array)
#1 /.../vendor/squizlabs/php_codesniffer/src/Files/File.php(496): SlevomatCodingStandard\Sniffs\TypeHints\NullableTypeForNullDefaultValueSniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 7)
#2 /.../vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(91): PHP_CodeSniffer\Files\File->process()
#3 / in /.../vendor/squizlabs/php_codesniffer/src/Runner.php on line 606
Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Undefined index: parenthesis_opener in /.../vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/NullableTypeForNullDefaultValueSniff.php on line 40 in /.../vendor/squizlabs/php_codesniffer/src/Runner.php on line 606
PHP_CodeSniffer\Exceptions\RuntimeException: Undefined index: parenthesis_opener in /.../vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/NullableTypeForNullDefaultValueSniff.php on line 40 in /.../vendor/squizlabs/php_codesniffer/src/Runner.php on line 606
Call Stack:
0.0017 401280 1. {main}() /.../vendor/squizlabs/php_codesniffer/bin/phpcbf:0
0.0487 1731048 2. PHP_CodeSniffer\Runner->runPHPCBF() /.../vendor/squizlabs/php_codesniffer/bin/phpcbf:18
0.3532 7546232 3. PHP_CodeSniffer\Runner->run() /.../vendor/squizlabs/php_codesniffer/src/Runner.php:200
0.3632 8086296 4. PHP_CodeSniffer\Runner->processFile() /.../vendor/squizlabs/php_codesniffer/src/Runner.php:434
0.3920 9037944 5. PHP_CodeSniffer\Reporter->cacheFileReport() /.../vendor/squizlabs/php_codesniffer/src/Runner.php:656
0.3921 9056624 6. PHP_CodeSniffer\Reports\Cbf->generateFileReport() /.../vendor/squizlabs/php_codesniffer/src/Reporter.php:285
0.3921 9056624 7. PHP_CodeSniffer\Fixer->fixFile() /.../vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php:49
0.3991 9155432 8. PHP_CodeSniffer\Files\LocalFile->process() /.../vendor/squizlabs/php_codesniffer/src/Fixer.php:174
0.3991 9155432 9. PHP_CodeSniffer\Files\LocalFile->process() /.../vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php:91
0.4003 9148152 10. SlevomatCodingStandard\Sniffs\TypeHints\NullableTypeForNullDefaultValueSniff->process() /.../vendor/squizlabs/php_codesniffer/src/Files/File.php:496
0.4006 9151216 11. PHP_CodeSniffer\Runner->handleErrors() /.../vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/NullableTypeForNullDefaultValueSniff.php:40 |
This issue isn't limited to array_reduce(
[],
static function (array $values): array {
return array_merge($values, []);
},
[]
); Edit: And another: static function (\InvalidArgumentException $exception): string {
return $exception->getMessage();
} |
Thank you for your report. It looks it's a bug in PHPCS itself but I've found a workaround for this sniff: d69ad4a |
Is there an open issue for phpcs for this issue? |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
There is an issue with the NullableTypeForNullDefaultValueSniff fixer, used on a closure with an array_filter. It is unable to properly transform this closure into an arrow function.
File to use when reproducing:
When running this fixer on the above code, it will iterate 3 times over it. The first two times through the
T_CLOSURE
, where the second time would be the culprit. The second iteration results in the following code, which breaks the third iteration, throwingUndefined index: parenthesis_opener
This clearly breaks the
array_filter
function, because somehow it converts it to an array. The following would be correct:In addition to that, the
StaticClosureSniff
will fail withUndefined index: scope_opener
on the above code, which would be correct.The text was updated successfully, but these errors were encountered: