Coding-standard: Undefined index issue on ControlStructureSpacingSniff with fixer

Created on 21 Sep 2018  路  5Comments  路  Source: slevomat/coding-standard

Since v4.8.0:

phpcbf -p --parallel=6 --standard=ruleset.xml

Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Undefined index:  in /home/developer/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/ControlStructureSpacingSniff.php on line 254 in /home/developer/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php:562
Stack trace:
#0 /home/developer/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/ControlStructureSpacingSniff.php(254): PHP_CodeSniffer\Runner->handleErrors(8, 'Undefined index...', '/home/developer...', 254, Array)
#1 /home/developer/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/ControlStructureSpacingSniff.php(210): SlevomatCodingStandard\Sniffs\ControlStructures\ControlStructureSpacingSniff->findControlStructureEnd(Object(PHP_CodeSniffer\Files\LocalFile), 149)
#2 /home/developer/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/ControlStructureSpacingSniff.php(137): SlevomatCodingSt in /home/developer/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php on line 562

Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Undefined variable: childOutput in /home/developer/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php on line 705 in /home/developer/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php:562
Stack trace:
#0 /home/developer/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(705): PHP_CodeSniffer\Runner->handleErrors(8, 'Undefined varia...', '/home/developer...', 705, Array)
#1 /home/developer/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(502): PHP_CodeSniffer\Runner->processChildProcs(Array)
#2 /home/developer/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(193): PHP_CodeSniffer\Runner->run()
#3 /home/developer/.composer/vendor/squizlabs/php_codesniffer/bin/phpcbf(18): PHP_CodeSniffer\Runner->runPHPCBF()
#4 {main}
  thrown in /home/developer/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php on line 562

Works like a charm on 4.7.3.

Git bisect revealed this commit: 93c582ce997e485f34e825f0950c042de980d35c

Here is also my ruleset configuration:

<?xml version="1.0"?>
<ruleset name="Standard">
    <file>src</file>
    <file>src-dev</file>
    <file>tests</file>
    <file>config</file>

    <exclude-pattern>tests/fixtures/repos</exclude-pattern>


    <rule ref="Generic.PHP.ForbiddenFunctions">
        <properties>
            <property
                name="forbiddenFunctions"
                type="array"
                value="
                    delete=>unset,
                    die=>null,
                    dump=>null,
                    echo=>null,
                    exit=>null,
                    print=>null,
                    sizeof=>count,
                    var_dump=>null
                "
            />
        </properties>
    </rule>

    <rule ref="PSR1"/>
    <rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
        <exclude-pattern>env.php</exclude-pattern>
    </rule>
    <rule ref="PSR2">
        <exclude name="Generic.Files.LineLength.TooLong"/>
        <exclude name="Generic.Files.LineLength.MaxExceeded"/>
    </rule>

    <rule ref="Squiz.Functions.GlobalFunction.Found">
        <exclude-pattern>src/functions.php</exclude-pattern>
    </rule>

    <rule ref="Symfony">
        <exclude name="Symfony.Commenting.License"/>
        <exclude name="Symfony.Commenting.Annotations.Invalid"/>
        <exclude name="Symfony.Commenting.ClassComment.Missing"/>
        <exclude name="Zend.NamingConventions.ValidVariableName.MemberVarContainsNumbers"/>
        <!-- @see https://github.com/djoos/Symfony-coding-standard/issues/120 -->
        <exclude name="Symfony.Commenting.FunctionComment"/>
        <!-- @see https://github.com/djoos/Symfony-coding-standard/issues/119 -->
        <exclude name="Symfony.Functions.ReturnType.Invalid"/>
        <!-- @see https://github.com/djoos/Symfony-coding-standard/issues/27 -->
        <exclude name="PEAR.Functions.FunctionCallSignature"/>
        <!-- @see https://github.com/djoos/Symfony-coding-standard/issues/44 -->
        <exclude name="Squiz.Strings.ConcatenationSpacing"/>
        <!-- @see https://github.com/djoos/Symfony-coding-standard/issues/122 -->
        <exclude name="Squiz.Functions.MultiLineFunctionDeclaration.ContentAfterBrace"/>
        <exclude name="Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore"/>
        <exclude name="PEAR.WhiteSpace.ScopeClosingBrace.Line"/>
        <exclude name="Symfony.Formatting.BlankLineBeforeReturn.Invalid"/>
        <!-- https://github.com/djoos/Symfony-coding-standard/issues/123 -->
        <exclude name="Symfony.Formatting.ReturnOrThrow.Invalid"/>
    </rule>

    <!-- @see https://github.com/djoos/Symfony-coding-standard/issues/121 -->
    <rule ref="Symfony.NamingConventions.ValidClassName.InvalidAbstractName">
        <exclude-pattern>*TestCase.php</exclude-pattern>
        <exclude-pattern>src/AppBundle/Entity/Operation.php</exclude-pattern>
    </rule>

    <rule ref="SlevomatCodingStandard">
        <exclude name="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"/>
        <exclude name="SlevomatCodingStandard.ControlStructures.DisallowEmpty"/>
        <exclude name="SlevomatCodingStandard.ControlStructures.DisallowShortTernaryOperator"/>
        <exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
        <exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/>
        <exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming"/>
        <exclude name="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment"/>
        <exclude name="SlevomatCodingStandard.Commenting.DocCommentSpacing.IncorrectLinesCountBetweenDifferentAnnotationsTypes"/>
        <exclude name="SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter"/>
        <exclude name="SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators"/>
        <!-- This rule should be enable later with a high diff review. -->
        <exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit"/>
        <exclude name="SlevomatCodingStandard.ControlStructures.NewWithoutParentheses"/>
        <exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation"/>
        <!-- @see https://github.com/slevomat/coding-standard/issues/245 -->
        <exclude name="SlevomatCodingStandard.Namespaces.UseOnlyWhitelistedNamespaces"/>
        <!-- @see https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/3471 -->
        <exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReNoValidateFormTypeExtension.phpferenceViaFullyQualifiedNameWithoutNamespace"/>
        <!-- @see https://github.com/slevomat/coding-standard/issues/246 -->
        <exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions.NonFullyQualifiedException"/>
        <!-- @see https://github.com/slevomat/coding-standard/issues/441 -->
        <exclude name="SlevomatCodingStandard.Commenting.UselessInheritDocComment.UselessInheritDocComment"/>
    </rule>
    <rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedMethod">
        <exclude-pattern>src/AppBundle/Command/OperationExecuteCommand.php</exclude-pattern>
    </rule>
    <rule ref="SlevomatCodingStandard.Classes.TraitUseSpacing">
        <properties>
            <property
                    name="linesCountBeforeFirstUse"
                    type="int"
                    value="0"
            />
        </properties>
    </rule>
    <rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
        <properties>
            <property
                name="rootNamespaces"
                type="array"
                value="
                    tests=>Tests,
                    src=>App,
                    src/AppBundle=>AppBundle,
                    src/PowerDNSBundle=>PowerDNSBundle,
                    src-dev=>Dev,
                "
            />
            <property name="ignoredNamespaces" type="array" value="DoctrineMigrations"/>
        </properties>
    </rule>
    <rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
        <properties>
            <property name="allowFullyQualifiedNameForCollidingClasses" value="true"/>
            <property name="allowFullyQualifiedGlobalClasses" value="true"/>
            <property name="allowFullyQualifiedGlobalFunctions" value="true"/>
            <property name="allowFullyQualifiedGlobalConstants" value="true"/>
        </properties>
    </rule>
    <rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName">
        <exclude-pattern>config/bundles.php</exclude-pattern>
        <exclude-pattern>src/Kernel.php</exclude-pattern>
    </rule>
    <rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
        <properties>
            <property name="searchAnnotations" value="true"/>
        </properties>
    </rule>
    <rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
        <properties>
            <property name="newlinesCountBetweenOpenTagAndDeclare" value="2"/>
            <property name="spacesCountAroundEqualsSign" value="0"/>
        </properties>
    </rule>
    <rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
        <properties>
            <property
                name="usefulAnnotations"
                type="array"
                value="
                    @after,
                    @before,
                    @dataProvider,
                    @deprecated,
                    @required,
                    @see,
                    @ApiDoc,
                    @Assert\,
                    @QueryParam,
                    @ORM\,
                    @ParamConverter,
                    @Route,
                    @Security,
                    @Method,
                    @IsGranted,
                    @Operation
                "
            />
            <property name="enableEachParameterAndReturnInspection" value="true"/>
        </properties>
    </rule>
    <rule ref="SlevomatCodingStandard.Types.EmptyLinesAroundTypeBraces">
        <properties>
            <property name="linesCountAfterOpeningBrace" value="0"/>
            <property name="linesCountBeforeClosingBrace" value="0"/>
        </properties>
    </rule>
</ruleset>
Bug

Most helpful comment

All 5 comments

@Soullivaneuh Impossible to fix without the code

@kukulich It fails with this output at the very beginning. What code should I provide and how?

Ok found it. Here is the output with -vvv option:

            Processing SlevomatCodingStandard\Sniffs\ControlStructures\ControlStructureSpacingSniff...  => Fixing file: 1/1 violations remaining---START FILE CONTENT---
 1|<?php
 2|
 3|declare(strict_types=1);
 4|
 5|use Doctrine\Common\Annotations\AnnotationReader;
 6|
 7|\error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED & ~\E_STRICT);
 8|\ini_set('display_errors', '0');
 9|
10|\mb_internal_encoding('UTF-8');
11|
12|\ini_set('memory_limit', '512M');
13|\ini_set('date.timezone', 'Europe/Paris');
14|
15|\define('KERNEL_PROJECT_DIR', __DIR__.'/..');
16|
17|// Change nested level max for xdebug
18|if (false !== \ini_get('xdebug.max_nesting_level')) {
19|    \ini_set('xdebug.max_nesting_level', '500');
20|}
21|
22|AnnotationReader::addGlobalIgnoredName('phpcsSuppress');
23|
24|// Needed for Browscap init.
25|$sharedPath = __DIR__.'/../var/shared';
26|if (!\file_exists($sharedPath)) {
27|    \mkdir($sharedPath);
28|}
29|
--- END FILE CONTENT ---
    => Changeset started by SlevomatCodingStandard\Sniffs\ControlStructures\ControlStructureSpacingSniff (line 189)
        Q: SlevomatCodingStandard\Sniffs\ControlStructures\ControlStructureSpacingSniff (line 198) replaced token 148 (T_WHITESPACE) "\nif" => "if"
        Q: SlevomatCodingStandard\Sniffs\ControlStructures\ControlStructureSpacingSniff (line 201) replaced token 147 (T_SEMICOLON) ";" => ";\n"
        Q: SlevomatCodingStandard\Sniffs\ControlStructures\ControlStructureSpacingSniff (line 201) replaced token 147 (T_SEMICOLON) ";" => ";\n\n"
        A: SlevomatCodingStandard\Sniffs\ControlStructures\ControlStructureSpacingSniff (line 203) replaced token 148 (T_WHITESPACE) "\nif" => "if"
        A: SlevomatCodingStandard\Sniffs\ControlStructures\ControlStructureSpacingSniff (line 203) replaced token 147 (T_SEMICOLON) ";" => ";\n\n"
    => Changeset ended: 2 changes applied

Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Undefined index:  in /home/developer/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/ControlStructureSpacingSniff.php on line 254 in /home/developer/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php:562
Stack trace:
#0 /home/developer/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/ControlStructureSpacingSniff.php(254): PHP_CodeSniffer\Runner->handleErrors(8, 'Undefined index...', '/home/developer...', 254, Array)
#1 /home/developer/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/ControlStructureSpacingSniff.php(210): SlevomatCodingStandard\Sniffs\ControlStructures\ControlStructureSpacingSniff->findControlStructureEnd(Object(PHP_CodeSniffer\Files\LocalFile), 149)
#2 /home/developer/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/ControlStructureSpacingSniff.php(137): SlevomatCodingSt in /home/developer/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php on line 562

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

enumag picture enumag  路  4Comments

donatj picture donatj  路  3Comments

Majkl578 picture Majkl578  路  3Comments

carusogabriel picture carusogabriel  路  5Comments

grogy picture grogy  路  5Comments