crazyfactory/php-sniffs

Got error after running phpcbf in new logistic

turbo8p opened this issue · 2 comments

Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Undefined offset: 302 in /var/www/project/vendor/crazyfactory/sniffs/src/CrazyFactory/Sniffs/ControlStructures/ControlSignatureSniff.php on line 233 in /var/www/project/vendor/squizlabs/php_codesniffer/src/Runner.php on line 543

PHP_CodeSniffer\Exceptions\RuntimeException: Undefined offset: 302 in /var/www/project/vendor/crazyfactory/sniffs/src/CrazyFactory/Sniffs/ControlStructures/ControlSignatureSniff.php on line 233 in /var/www/project/vendor/squizlabs/php_codesniffer/src/Runner.php on line 543

Call Stack:
    0.0004     354304   1. {main}() /var/www/project/vendor/squizlabs/php_codesniffer/bin/phpcbf:0
    0.0189     365640   2. PHP_CodeSniffer\Runner->runPHPCBF() /var/www/project/vendor/squizlabs/php_codesniffer/bin/phpcbf:18
    0.1998     891680   3. PHP_CodeSniffer\Runner->run() /var/www/project/vendor/squizlabs/php_codesniffer/src/Runner.php:186
    0.3285    1125576   4. PHP_CodeSniffer\Runner->processFile() /var/www/project/vendor/squizlabs/php_codesniffer/src/Runner.php:383
    0.3402    1372984   5. PHP_CodeSniffer\Reporter->cacheFileReport() /var/www/project/vendor/squizlabs/php_codesniffer/src/Runner.php:592
    0.3403    1391464   6. PHP_CodeSniffer\Reports\Cbf->generateFileReport() /var/www/project/vendor/squizlabs/php_codesniffer/src/Reporter.php:261
    0.3403    1391464   7. PHP_CodeSniffer\Fixer->fixFile() /var/www/project/vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php:47
    0.3415    1410608   8. PHP_CodeSniffer\Files\LocalFile->process() /var/www/project/vendor/squizlabs/php_codesniffer/src/Fixer.php:179
    0.3415    1410608   9. PHP_CodeSniffer\Files\File->process() /var/www/project/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php:94
    0.3501    1615480  10. CrazyFactory\Sniffs\ControlStructures\ControlSignatureSniff->process() /var/www/project/vendor/squizlabs/php_codesniffer/src/Files/File.php:431
    0.3501    1615512  11. CrazyFactory\Sniffs\ControlStructures\ControlSignatureSniff->requireNewLineAfterBrace() /var/www/project/vendor/crazyfactory/sniffs/src/CrazyFactory/Sniffs/ControlStructures/ControlSignatureSniff.php:140
    0.3501    1616416  12. PHP_CodeSniffer\Runner->handleErrors() /var/www/project/vendor/crazyfactory/sniffs/src/CrazyFactory/Sniffs/ControlStructures/ControlSignatureSniff.php:233

The error occurs when closing brace is before last character of the file and last character is white space of new line.

// Handle incoming arguments
try {
    $console->handle($arguments);
} catch (Throwable $e) {
    echo "\nFATAL: {$e->getMessage()}\n";

    echo $e->getFile().':'.$e->getLine()."\n\n";
    echo $e->getTraceAsString();
    exit(255);
}

Fixed #13