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.66k stars 1.48k forks source link

(v.3.4.0) PHPCBF conflict with FunctionCallSignatureSniff and ArrayDeclarationSniff #2442

Closed johnsaigle closed 5 years ago

johnsaigle commented 5 years ago

I am getting a FAILED TO FIX error on code that has this shape. There are a few places in the codebase that I work on where we use this structure of calling functions using an associative array parameter that is in turn created by another function call:

        parent::__construct(
            new \ArrayIterator(
                [
                 "/css/"    => new \LORIS\Router\ModuleFileRouter(
                     $this,
                     $moduledir,
                     "css",
                     "text/css"
                 ),
                 "/js/"     => new \LORIS\Router\ModuleFileRouter(
                     $this,
                     $moduledir,
                     "js",
                     "application/javascript"
                 ),
                 "/static/" => new \LORIS\Router\ModuleFileRouter(
                     $this,
                     $moduledir,
                     "static",
                     ""
                 ),
                ]
            )
        );

The problem reduces to this example:

foo(
    array(
        "key" => aVeryLongFunctionCallThatExceedsOurLineLengthLimitsOf80Chars(
            $fairlyLongParam,
            $fairlyLongParam2
        )
    )
);

When using phpcbf -vv ... I see errors with a conflict between the rules PHP_CodeSniffer\Standards\PEAR\Sniffs\Functions\FunctionCallSignatureSniff and PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff.

gsherwood commented 5 years ago

I can't replicate any conflicts on the code you've supplied, either on 3.4.0 or the latest 3.4.1 version.

I'm testing using this command to limit the checks: phpcs temp.php --standard=Squiz,PEAR --sniffs=PEAR.Functions.FunctionCallSignature,Squiz.Arrays.ArrayDeclaration --report=diff -vv

It's possible that these sniffs do not conflict directly on this code, but instead conflict on a different code structure that has been created during fixing by other sniffs. If you use -vvv while running PHPCS with the diff report, you'll see how the file content changes after each loop and you may be able to find the code snippet that is causing the problem.

johnsaigle commented 5 years ago

Okay thanks for the feedback. I'll do some more testing and report back with the output of -vvv

gsherwood commented 5 years ago

Closing due to no feedback. Please post again if this is still an issue and you have more debug output.