Skip to content

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Apr 17, 2025

Description

As things were, using extend="true" when setting an array property in a ruleset XML file could only extend another array property setting set in an (included) ruleset file.

A potential default array value set on the sniff itself could not be extended.

This commit changes this behaviour.
If a default array value is defined on a sniff, setting additional array values via a ruleset with extend="true" will now add these values to the pre-existing sniff property default value.

This also now allows for redefining the array value for a predefined associative key.

Includes plenty of tests documenting and safeguarding the feature.

Suggested changelog entry

Support for extending a default value for an array property on a sniff from an XML ruleset file.
- Previously, using extend="true" on an property tag for setting an array value could already extend a property value set elsewhere in an (inluded) ruleset.
- Now, you can also add to (extend) a default value as set on the sniff itself.
- Note: the property default value and the values set via the ruleset will be merged.
- This also means that for associative arrays, you can redefine the value for a particular array key.
- For numerically indexed arrays, this means the array will be renumbered. Keep this in mind if the numeric indexes hold meaning.

Related issues/external references

Fixes #15

@jrfnl
Copy link
Member Author

jrfnl commented Apr 17, 2025

Just saw I cherrypicked an outdated commit. Fixed up now.

@jrfnl jrfnl force-pushed the phpcs-4.0/feature/15-property-array-extend-original-sniff-property-value branch from c5728e4 to 7fa3bc5 Compare April 17, 2025 21:57
jrfnl added 2 commits April 18, 2025 15:26
As things were, using `extend="true"` when setting an array property in a ruleset XML file could only extend another array property setting set in an (included) ruleset file.

A potential default array value set on the sniff itself could not be extended.

This commit changes this behaviour.
If a default array value is defined on a sniff, setting additional array values via a ruleset with `extend="true"` will now add these values to the pre-existing sniff property default value.

This also now allows for redefining the array _value_ for a predefined associative key.

Includes plenty of tests documenting and safeguarding the feature.

Fixes 15
@jrfnl jrfnl force-pushed the phpcs-4.0/feature/15-property-array-extend-original-sniff-property-value branch from 7fa3bc5 to 5dc0297 Compare April 18, 2025 13:27
@jrfnl jrfnl merged commit 7a3c1e3 into 4.x Apr 18, 2025
148 checks passed
@jrfnl jrfnl deleted the phpcs-4.0/feature/15-property-array-extend-original-sniff-property-value branch April 18, 2025 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant