squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.67k stars 1.48k forks source link

PHPCBF Undefined array key "scope_closer" #3586

Closed michnovka closed 2 years ago

michnovka commented 2 years ago

Describe the bug A clear and concise description of what the bug is.

Code sample

<?php

class X
{
    public function __construct(
    )
    {}
}

Custom ruleset

<?xml version="1.0" encoding="UTF-8"?>

<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

    <arg name="basepath" value="."/>
    <arg name="cache" value=".phpcs-cache"/>
    <arg name="colors"/>
    <arg name="extensions" value="php"/>
    <arg name="encoding" value="utf-8"/>
    <arg name="parallel" value="64"/>

    <config name="php_version" value="80100"/>

    <config name="installed_paths" value="../../slevomat/coding-standard,../../wp-coding-standards/wpcs,../../../phpcs"/>

    <file>src/</file>
    <file>tests/</file>

    <!-- PSR12 is the default standard-->
    <rule ref="PSR12"/>

    <rule ref="SlevomatCodingStandard.Namespaces.UnusedUses"/>

</ruleset>

PHPCS output here

PHP Fatal error:  Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Undefined array key "scope_closer" in /home/superuser/Astrill/project--core/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php on line 193 in /home/superuser/Astrill/project--core/vendor/squizlabs/php_codesniffer/src/Runner.php:607
Stack trace:
#0 /home/superuser/Astrill/project--core/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php(193): PHP_CodeSniffer\Runner->handleErrors()
#1 /home/superuser/Astrill/project--core/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/SniffLocalCache.php(42): SlevomatCodingStandard\Helpers\UseStatementHelper::SlevomatCodingStandard\Helpers\{closure}()
#2 /home/superuser/Astrill/project--core/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/SniffLocalCache.php(31): SlevomatCodingStandard\Helpers\SniffLocalCache::setIfNotCached()
#3 /home/superuser/Astrill/project--core/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php(207): SlevomatCodingStandard\Helpers\SniffLocalCache::getAndSetIfNotCached()
#4 /home/superuser/Astrill/project--core/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php(123): SlevomatCodingStandard\Helpers\UseStatementHelper::getUseStatementPointers()
#5 /home/superuser/Astrill/project--core/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/SniffLocalCache.php(42): SlevomatCodingStandard\Helpers\UseStatementHelper::SlevomatCodingStandard\Helpers\{closure}()
#6 /home/superuser/Astrill/project--core/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/SniffLocalCache.php(31): SlevomatCodingStandard\Helpers\SniffLocalCache::setIfNotCached()
#7 /home/superuser/Astrill/project--core/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php(157): SlevomatCodingStandard\Helpers\SniffLocalCache::getAndSetIfNotCached()
#8 /home/superuser/Astrill/project--core/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/UnusedUsesSniff.php(87): SlevomatCodingStandard\Helpers\UseStatementHelper::getFileUseStatements()
#9 /home/superuser/Astrill/project--core/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): SlevomatCodingStandard\Sniffs\Namespaces\UnusedUsesSniff->process()
#10 /home/superuser/Astrill/project--core/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
#11 /home/superuser/Astrill/project--core/vendor/squizlabs/php_codesniffer/src/Fixer.php(174): PHP_CodeSniffer\Files\LocalFile->process()
#12 /home/superuser/Astrill/project--core/vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php(52): PHP_CodeSniffer\Fixer->fixFile()
#13 /home/superuser/Astrill/project--core/vendor/squizlabs/php_codesniffer/src/Reporter.php(285): PHP_CodeSniffer\Reports\Cbf->generateFileReport()
#14 /home/superuser/Astrill/project--core/vendor/squizlabs/php_codesniffer/src/Runner.php(657): PHP_CodeSniffer\Reporter->cacheFileReport()
#15 /home/superuser/Astrill/project--core/vendor/squizlabs/php_codesniffer/src/Runner.php(503): PHP_CodeSniffer\Runner->processFile()
#16 /home/superuser/Astrill/project--core/vendor/squizlabs/php_codesniffer/src/Runner.php(200): PHP_CodeSniffer\Runner->run()
#17 /home/superuser/Astrill/project--core/vendor/squizlabs/php_codesniffer/bin/phpcbf(18): PHP_CodeSniffer\Runner->runPHPCBF()
#18 {main}
  thrown in /home/superuser/Astrill/project--core/vendor/squizlabs/php_codesniffer/src/Runner.php on line 607
PHP Fatal error:  Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: One or more child processes failed to run in /home/superuser/Astrill/project--core/vendor/squizlabs/php_codesniffer/src/Runner.php:545
Stack trace:
#0 /home/superuser/Astrill/project--core/vendor/squizlabs/php_codesniffer/src/Runner.php(200): PHP_CodeSniffer\Runner->run()
#1 /home/superuser/Astrill/project--core/vendor/squizlabs/php_codesniffer/bin/phpcbf(18): PHP_CodeSniffer\Runner->runPHPCBF()
#2 {main}
  thrown in /home/superuser/Astrill/project--core/vendor/squizlabs/php_codesniffer/src/Runner.php on line 545

Expected behavior Nothing should happen

Versions (please complete the following information):

Additional notes PHPCS works fine, its PHPCBF that fails

jrfnl commented 2 years ago

@michnovka Looks like the sniff in the Slevomat standard is missing some defensive coding. Please report this to the Slevomat Standard.