False positive of php:S1788 for default value plus variable-length argument list

28 views
Skip to first unread message

kwe...@gmail.com

unread,
Mar 4, 2016, 8:41:39 AM3/4/16
to SonarQube
This code triggers the rule php:S1788 'Method arguments with default value should be last':

public function __construct($name, $attributes = array(), ...$children) {

The method signature combines an argument with a default value, $attributes, with an argument with variable number of values, $children.

Defining it this way allows a flexible way to call it with 1, 2, 3 or more arguments.

The $children argument has to be the last argument because it captures all values passed after the first 2. This makes it impossible to move the $attributes argument after $children.

It would be nice if this situation could be detected and not treat it as a violation of the php:S1788 rule.


rob schlüter

Elena Vilchik

unread,
Mar 4, 2016, 11:34:20 AM3/4/16
to SonarQube, kwe...@gmail.com
Hi Rob,

Thanks for this feedback. I've created a ticket https://jira.sonarsource.com/browse/SONARPHP-615.

Elena VILCHIK | 
SonarSource
Language Team
Reply all
Reply to author
Forward
0 new messages