Skip to content

Failures in child processes are not handled by the runner #2142

Closed
@morozov

Description

@morozov

Unfortunately, I don't know how to reproduce this issue with the OOTB standards, but here's the minimal required setup:

cat > composer.json << 'EOF'
{
    "require-dev": {
        "doctrine/coding-standard": "^4.0"
    }
}
EOF

cat > phpcs.xml.dist << 'EOF'
<?xml version="1.0"?>
<ruleset>
    <rule ref="Doctrine"/>
</ruleset>
EOF

cat > PhpCodeSnifferFailure.php << 'EOF'
<?php

namespace Doctrine\DBAL;

class PhpCodeSnifferFailure
{
    public function foo()
    {
        return [
        <<<HERE
HERE
            ,
        ];
    }
}
EOF

composer install

vendor/bin/phpcs --version
# PHP_CodeSniffer version 3.3.1 (stable) by Squiz (http://www.squiz.net)

vendor/bin/phpcbf --parallel=2 PhpCodeSnifferFailure.php

The run results in the following error:

  1. PHP_CodeSniffer\Exceptions\RuntimeException: Undefined index: scope_closer in vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php on line 156 in /home/morozov/t1/vendor/squizlabs/php_codesniffer/src/Runner.php on line 562

    This error happens in the child process outside of the PHP_CodeSniffer codebase because the T_CLASS token doesn't have the scope_closer attribute defined.

  2. PHP_CodeSniffer\Exceptions\RuntimeException: Undefined variable: childOutput in vendor/squizlabs/php_codesniffer/src/Runner.php on line 705 in vendor/squizlabs/php_codesniffer/src/Runner.php on line 562

    This error happens in PHP_CodeSniffer itself. The parent creates an empty shared file before running the child:

    $childOutFilename = tempnam(sys_get_temp_dir(), 'phpcs-child');

    but the child dies before writing its contents due to the error above. However, the parent only checks if the file exists:

    if (file_exists($procData['out']) === true) {

Besides the bug in the runner, is the fact that a T_CLASS token doesn't have scope_closer also a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions