Skip to content

Feature request: Array property extending doesn't work when property has default value #15

Closed
@jrfnl

Description

@jrfnl

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 the forbiddenFunctions property in a standard and then extend 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


Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions