Skip to content

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Aug 8, 2025

Description

When array properties are set inline to one of the "special" values, i.e. true, false or null, this would not be handled correctly and always result in an empty array.

While it is highly debatable that this is something which will ever occur in real-life, as setting an array property like that would not give a sniff any usable information - basically the property should not have been an array property in that case -, it should still be handled correctly by the ruleset class.

Fixed now.

Includes additional tests.

Props to @rodrigoprimo for coming up with this scenario.

Suggested changelog entry

N/A This is basically already covered by the changelog entry for #1006

When array properties are set inline to one of the "special" values, i.e. `true`, `false` or `null`, this would not be handled correctly and always result in an empty array.

While it is highly debatable that this is something which will ever occur in real-life, as setting an array property like that would not give a sniff any usable information - basically the property should not have been an array property in that case -, it should still be handled correctly by the ruleset class.

Fixed now.

Includes additional tests.
@jrfnl jrfnl force-pushed the phpcs-4.0/inline-property-handling-tweak branch from ff12ff2 to 23546f6 Compare August 8, 2025 15:26
@jrfnl jrfnl merged commit 9951290 into 4.x Aug 8, 2025
65 checks passed
@jrfnl jrfnl deleted the phpcs-4.0/inline-property-handling-tweak branch August 8, 2025 16:07
rodrigoprimo added a commit to rodrigoprimo/WordPress-Coding-Standards that referenced this pull request Aug 18, 2025
Add a new error when validating prefixes if a prefix is not a string or is an empty string.

This is necessary in preparation for PHPCS 4.0. Starting with this version, array properties can have types other than string, and the sniff needs to be updated to handle non-string prefixes.

Using the same error when the string is empty made sense as before the sniff would generate an error complaining about the length of the prefix.

TODO: the value of the prefix is type casted to a string when displaying the error message. For example, `true` becomes `1`. I need to think if this is a problem or not.

Also, if `true` is passed as the first and only element of an array property there seems to be an error in PHPCS.

Check how PHPCSStandards/PHP_CodeSniffer#1172 and PHPCSStandards/PHP_CodeSniffer#1193 impact this commit.
rodrigoprimo added a commit to rodrigoprimo/WordPress-Coding-Standards that referenced this pull request Aug 21, 2025
Add a new error when validating prefixes if a prefix is not a string or is an empty string.

This is necessary in preparation for PHPCS 4.0. Starting with this version, array properties can have types other than string, and the sniff needs to be updated to handle non-string prefixes.

Using the same error when the string is empty made sense as before the sniff would generate an error complaining about the length of the prefix.

TODO: the value of the prefix is type casted to a string when displaying the error message. For example, `true` becomes `1`. I need to think if this is a problem or not.

Also, if `true` is passed as the first and only element of an array property there seems to be an error in PHPCS.

Check how PHPCSStandards/PHP_CodeSniffer#1172 and PHPCSStandards/PHP_CodeSniffer#1193 impact this commit.
rodrigoprimo added a commit to rodrigoprimo/WordPress-Coding-Standards that referenced this pull request Aug 21, 2025
Add a new error when validating prefixes if a prefix is not a string or is an empty string.

This is necessary in preparation for PHPCS 4.0. Starting with this version, array properties can have types other than string, and the sniff needs to be updated to handle non-string prefixes.

Using the same error when the string is empty made sense as before the sniff would generate an error complaining about the length of the prefix.

TODO: the value of the prefix is type casted to a string when displaying the error message. For example, `true` becomes `1`. I need to think if this is a problem or not.

Also, if `true` is passed as the first and only element of an array property there seems to be an error in PHPCS.

Check how PHPCSStandards/PHP_CodeSniffer#1172 and PHPCSStandards/PHP_CodeSniffer#1193 impact this commit.
rodrigoprimo added a commit to rodrigoprimo/WordPress-Coding-Standards that referenced this pull request Sep 10, 2025
Add a new error when validating prefixes if a prefix is not a string or is an empty string.

This is necessary in preparation for PHPCS 4.0. Starting with this version, array properties can have types other than string, and the sniff needs to be updated to handle non-string prefixes.

Using the same error when the string is empty made sense as before the sniff would generate an error complaining about the length of the prefix.

TODO: the value of the prefix is type casted to a string when displaying the error message. For example, `true` becomes `1`. I need to think if this is a problem or not.

Also, if `true` is passed as the first and only element of an array property there seems to be an error in PHPCS.

Check how PHPCSStandards/PHP_CodeSniffer#1172 and PHPCSStandards/PHP_CodeSniffer#1193 impact this commit.
rodrigoprimo added a commit to rodrigoprimo/WordPress-Coding-Standards that referenced this pull request Sep 15, 2025
Add a new error when validating prefixes if a prefix is not a string or is an empty string.

This is necessary in preparation for PHPCS 4.0. Starting with this version, array properties can have types other than string, and the sniff needs to be updated to handle non-string prefixes.

Using the same error when the string is empty made sense as before the sniff would generate an error complaining about the length of the prefix.

TODO: the value of the prefix is type casted to a string when displaying the error message. For example, `true` becomes `1`. I need to think if this is a problem or not.

Also, if `true` is passed as the first and only element of an array property there seems to be an error in PHPCS.

Check how PHPCSStandards/PHP_CodeSniffer#1172 and PHPCSStandards/PHP_CodeSniffer#1193 impact this commit.
rodrigoprimo added a commit to rodrigoprimo/WordPress-Coding-Standards that referenced this pull request Sep 16, 2025
Add a new error when validating prefixes if a prefix is not a string or is an empty string.

This is necessary in preparation for PHPCS 4.0. Starting with this version, array properties can have types other than string, and the sniff needs to be updated to handle non-string prefixes.

Using the same error when the string is empty made sense as before the sniff would generate an error complaining about the length of the prefix.

TODO: the value of the prefix is type casted to a string when displaying the error message. For example, `true` becomes `1`. I need to think if this is a problem or not.

Also, if `true` is passed as the first and only element of an array property there seems to be an error in PHPCS.

Check how PHPCSStandards/PHP_CodeSniffer#1172 and PHPCSStandards/PHP_CodeSniffer#1193 impact this commit.
rodrigoprimo added a commit to rodrigoprimo/WordPress-Coding-Standards that referenced this pull request Sep 17, 2025
Add a new error when validating prefixes if a prefix is not a string or is an empty string.

This is necessary in preparation for PHPCS 4.0. Starting with this version, array properties can have types other than string, and the sniff needs to be updated to handle non-string prefixes.

Using the same error when the string is empty made sense as before the sniff would generate an error complaining about the length of the prefix.

TODO: the value of the prefix is type casted to a string when displaying the error message. For example, `true` becomes `1`. I need to think if this is a problem or not.

Also, if `true` is passed as the first and only element of an array property there seems to be an error in PHPCS.

Check how PHPCSStandards/PHP_CodeSniffer#1172 and PHPCSStandards/PHP_CodeSniffer#1193 impact this commit.
rodrigoprimo added a commit to rodrigoprimo/WordPress-Coding-Standards that referenced this pull request Sep 19, 2025
Add a new error when validating prefixes if a prefix is not a string or is an empty string.

This is necessary in preparation for PHPCS 4.0. Starting with this version, array properties can have types other than string, and the sniff needs to be updated to handle non-string prefixes.

Using the same error when the string is empty made sense as before the sniff would generate an error complaining about the length of the prefix.

TODO: the value of the prefix is type casted to a string when displaying the error message. For example, `true` becomes `1`. I need to think if this is a problem or not.

Also, if `true` is passed as the first and only element of an array property there seems to be an error in PHPCS.

Check how PHPCSStandards/PHP_CodeSniffer#1172 and PHPCSStandards/PHP_CodeSniffer#1193 impact this commit.
rodrigoprimo added a commit to rodrigoprimo/WordPress-Coding-Standards that referenced this pull request Sep 19, 2025
Add a new error when validating prefixes if a prefix is not a string or is an empty string.

This is necessary in preparation for PHPCS 4.0. Starting with this version, array properties can have types other than string, and the sniff needs to be updated to handle non-string prefixes.

Using the same error when the string is empty made sense as before the sniff would generate an error complaining about the length of the prefix.

TODO: the value of the prefix is type casted to a string when displaying the error message. For example, `true` becomes `1`. I need to think if this is a problem or not.

Also, if `true` is passed as the first and only element of an array property there seems to be an error in PHPCS.

Check how PHPCSStandards/PHP_CodeSniffer#1172 and PHPCSStandards/PHP_CodeSniffer#1193 impact this commit.
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.

2 participants