Closed
Description
Repost from squizlabs/PHP_CodeSniffer#2228:
PR squizlabs/PHP_CodeSniffer#2154 added support for array properties being extended, however it appears that this doesn't work when an array property already has a default value set.
If we take the original example of the
Generic.PHP.ForbiddenFunctions
sniff, it all works correctly if you overrule theforbiddenFunctions
property in a standard and thenextend
it from a project-based ruleset.However, if you want to extend the default values of the
forbiddenFunctions
property:public $forbiddenFunctions = [ 'sizeof' => 'count', 'delete' => 'unset', ];either via a standard or a project ruleset:
<rule ref="Generic.PHP.ForbiddenFunctions"> <properties> <property name="forbiddenFunctions" type="array" extend="true"> <element key="foo" value="fixedFoo"/> <element key="bar" value="fixedBar"/> </property> </properties> </rule>You end up with:
public $forbiddenFunctions = [ 'foo' => 'fixedFoo', 'bar' => 'fixedBar', ];instead of the expected:
public $forbiddenFunctions = [ 'sizeof' => 'count', 'delete' => 'unset', 'foo' => 'fixedFoo', 'bar' => 'fixedBar', ];Related squizlabs/PHP_CodeSniffer#2153