Skip to content

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

Closed as not planned
@jrfnl

Description

@jrfnl

PR #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',
];

@Majkl578 Any thoughts on this ?

Related #2153

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Ready for Release

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions