djoos / Symfony-coding-standard

Development repository for the Symfony coding standard
MIT License
402 stars 102 forks source link

Fix MultiLineArrayCommaSniff for PHP 8.3 #199

Closed brianvarskonst closed 1 month ago

brianvarskonst commented 6 months ago

Hello,

I got this following error by running vendor/bin/phpcbf:

PHP Fatal error:  Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Increment on type bool has no effect, this will change in the next major version of PHP in /var/www/html/app/vendor/escapestudios/symfony2-coding-standard/Symfony/Sniffs/Arrays/MultiLineArrayCommaSniff.php on line 97 in /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php:623
Stack trace:
#0 /var/www/html/app/vendor/escapestudios/symfony2-coding-standard/Symfony/Sniffs/Arrays/MultiLineArrayCommaSniff.php(97): PHP_CodeSniffer\Runner->handleErrors()
#1 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Files/File.php(519): Symfony\Sniffs\Arrays\MultiLineArrayCommaSniff->process()
#2 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
#3 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Fixer.php(175): PHP_CodeSniffer\Files\LocalFile->process()
#4 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php(52): PHP_CodeSniffer\Fixer->fixFile()
#5 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Reporter.php(285): PHP_CodeSniffer\Reports\Cbf->generateFileReport()
#6 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php(706): PHP_CodeSniffer\Reporter->cacheFileReport()
#7 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php(519): PHP_CodeSniffer\Runner->processFile()
#8 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php(215): PHP_CodeSniffer\Runner->run()
#9 /var/www/html/app/vendor/squizlabs/php_codesniffer/bin/phpcbf(14): PHP_CodeSniffer\Runner->runPHPCBF()
#10 /var/www/html/app/vendor/bin/phpcbf(119): include('...')
#11 {main}
  thrown in /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php on line 623

Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Increment on type bool has no effect, this will change in the next major version of PHP in /var/www/html/app/vendor/escapestudios/symfony2-coding-standard/Symfony/Sniffs/Arrays/MultiLineArrayCommaSniff.php on line 97 in /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php:623
Stack trace:
#0 /var/www/html/app/vendor/escapestudios/symfony2-coding-standard/Symfony/Sniffs/Arrays/MultiLineArrayCommaSniff.php(97): PHP_CodeSniffer\Runner->handleErrors()
#1 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Files/File.php(519): Symfony\Sniffs\Arrays\MultiLineArrayCommaSniff->process()
#2 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
#3 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Fixer.php(175): PHP_CodeSniffer\Files\LocalFile->process()
#4 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php(52): PHP_CodeSniffer\Fixer->fixFile()
#5 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Reporter.php(285): PHP_CodeSniffer\Reports\Cbf->generateFileReport()
#6 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php(706): PHP_CodeSniffer\Reporter->cacheFileReport()
#7 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php(519): PHP_CodeSniffer\Runner->processFile()
#8 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php(215): PHP_CodeSniffer\Runner->run()
#9 /var/www/html/app/vendor/squizlabs/php_codesniffer/bin/phpcbf(14): PHP_CodeSniffer\Runner->runPHPCBF()
#10 /var/www/html/app/vendor/bin/phpcbf(119): include('...')
#11 {main}
  thrown in /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php on line 623
PHP Fatal error:  Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Increment on type bool has no effect, this will change in the next major version of PHP in /var/www/html/app/vendor/escapestudios/symfony2-coding-standard/Symfony/Sniffs/Arrays/MultiLineArrayCommaSniff.php on line 97 in /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php:623
Stack trace:
#0 /var/www/html/app/vendor/escapestudios/symfony2-coding-standard/Symfony/Sniffs/Arrays/MultiLineArrayCommaSniff.php(97): PHP_CodeSniffer\Runner->handleErrors()
#1 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Files/File.php(519): Symfony\Sniffs\Arrays\MultiLineArrayCommaSniff->process()
#2 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
#3 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Fixer.php(175): PHP_CodeSniffer\Files\LocalFile->process()
#4 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php(52): PHP_CodeSniffer\Fixer->fixFile()
#5 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Reporter.php(285): PHP_CodeSniffer\Reports\Cbf->generateFileReport()
#6 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php(706): PHP_CodeSniffer\Reporter->cacheFileReport()
#7 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php(519): PHP_CodeSniffer\Runner->processFile()
#8 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php(215): PHP_CodeSniffer\Runner->run()
#9 /var/www/html/app/vendor/squizlabs/php_codesniffer/bin/phpcbf(14): PHP_CodeSniffer\Runner->runPHPCBF()
#10 /var/www/html/app/vendor/bin/phpcbf(119): include('...')
#11 {main}
  thrown in /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php on line 623

Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Increment on type bool has no effect, this will change in the next major version of PHP in /var/www/html/app/vendor/escapestudios/symfony2-coding-standard/Symfony/Sniffs/Arrays/MultiLineArrayCommaSniff.php on line 97 in /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php:623
Stack trace:
#0 /var/www/html/app/vendor/escapestudios/symfony2-coding-standard/Symfony/Sniffs/Arrays/MultiLineArrayCommaSniff.php(97): PHP_CodeSniffer\Runner->handleErrors()
#1 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Files/File.php(519): Symfony\Sniffs\Arrays\MultiLineArrayCommaSniff->process()
#2 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
#3 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Fixer.php(175): PHP_CodeSniffer\Files\LocalFile->process()
#4 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php(52): PHP_CodeSniffer\Fixer->fixFile()
#5 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Reporter.php(285): PHP_CodeSniffer\Reports\Cbf->generateFileReport()
#6 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php(706): PHP_CodeSniffer\Reporter->cacheFileReport()
#7 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php(519): PHP_CodeSniffer\Runner->processFile()
#8 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php(215): PHP_CodeSniffer\Runner->run()
#9 /var/www/html/app/vendor/squizlabs/php_codesniffer/bin/phpcbf(14): PHP_CodeSniffer\Runner->runPHPCBF()
#10 /var/www/html/app/vendor/bin/phpcbf(119): include('...')
#11 {main}
  thrown in /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php on line 623
PHP Fatal error:  Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: One or more child processes failed to run in /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php:561
Stack trace:
#0 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php(215): PHP_CodeSniffer\Runner->run()
#1 /var/www/html/app/vendor/squizlabs/php_codesniffer/bin/phpcbf(14): PHP_CodeSniffer\Runner->runPHPCBF()
#2 /var/www/html/app/vendor/bin/phpcbf(119): include('...')
#3 {main}
  thrown in /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php on line 561

Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: One or more child processes failed to run in /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php:561
Stack trace:
#0 /var/www/html/app/vendor/squizlabs/php_codesniffer/src/Runner.php(215): PHP_CodeSniffer\Runner->run()
#1 /var/www/html/app/vendor/squizlabs/php_codesniffer/bin/phpcbf(14): PHP_CodeSniffer\Runner->runPHPCBF()
#2 /var/www/html/app/vendor/bin/phpcbf(119): include('...')
#3 {main}

This error appears because the line of code return a boolean or an integer and for PHP 8.3 its deprecaded to increase a boolean, so this early return fixes this issue.

/** @return false|int */
$lastCommaPtr = $phpcsFile->findPrevious(
     T_COMMA,
     $closePtr,
     $stackPtr
);
mmoll commented 1 month ago

@djoos could this get merged and released, please? It's starting to hurt... 🤒

djoos commented 1 month ago

Apologies for the late response. Merged - will get a new version out shortly.

djoos commented 1 month ago

Thank you for the contribution @brianvarskonst - and the nudge by @mmoll!

mmoll commented 1 month ago

@djoos unfortunately this also introducted a bug, could you please enable GitHub Actions in this repository and merge #201 to prevent failures in the future? #202 is the bugfix after that.

djoos commented 1 month ago

Thank you @mmoll!