PHP Plugin: PSR-2 coding style checker too strict on multi-line arguments

693 views
Skip to first unread message

lukas.b...@kyto.com

unread,
Feb 15, 2016, 10:00:29 AM2/15/16
to SonarQube
Hi,

I want to report an issue of the PSR-2 coding style checker regarding the splitting of multi-line arguments:

Sample code snippets which are reported as errors:

        $dates = array_map(function ($arr) {
// Either split this list into multiple lines, aligned at column "12" or put all arguments on line "45"
            return $arr['date'];
        }, $visits);
// Move the closing parenthesis on the next line.


        $form = $this->createForm(new TranslationKeyType(), $entity, array(
// Either split this list into multiple lines, aligned at column "12" or put all arguments on line "101".
            'action' => $this->generateUrl('translation_create'),
            'method' => 'POST'
        ));


However, in the addendum of PSR-2 it is stated that:

Using one or more multi-line arguments (i.e: arrays or anonymous functions) does not constitute splitting the argument list itself, therefore Section 4.6 is not automatically enforced. Arrays and anonymous functions are able to span multiple lines.




Would be great if this can be accepted as well.


Thanks,
Lukas

lukas.b...@kyto.com

unread,
Feb 29, 2016, 10:59:28 AM2/29/16
to SonarQube, lukas.b...@kyto.com
Did anyone have time to check and hopefully accept this yet?

Elena Vilchik

unread,
Mar 1, 2016, 3:30:54 AM3/1/16
to SonarQube, lukas.b...@kyto.com
Hello Lukas,

Thanks a lot for the feedback and sorry for the delay. I've created the ticket to fix this issue https://jira.sonarsource.com/browse/SONARPHP-611.
Elena VILCHIK | SonarSource
Language Team

lukas.b...@kyto.com

unread,
Jan 10, 2017, 10:14:05 AM1/10/17
to SonarQube, lukas.b...@kyto.com
Hello Elena,

we were very happy to see the issue fixed last year, many thanks for this.

I just stumbled across a case where it does not seem to work properly though - correct me if I'm wrong:

// The following gives "Either split this list into multiple lines..."
somefunction($foo, $bar, array(
    // ...
), $baz);

// the following is fine
somefunction($foo, $bar, [
    // ...
], $baz);


Thanks,
Lukas

Elena Vilchik

unread,
Feb 23, 2017, 5:50:37 AM2/23/17
to SonarQube, lukas.b...@kyto.com
Hello,

Indeed, in our improvement we included only short array syntax. I hope to fix it soon https://jira.sonarsource.com/browse/SONARPHP-685.

Thanks for feedback! 

Elena VILCHIK | SonarSource
Language Team



Reply all
Reply to author
Forward
0 new messages