Skip to content

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Apr 6, 2025

Description

Squiz/OperatorBracket: remove some redundancy

The % modulus token is included in the Tokens::$operators array. No need to add it separately.

Squiz/OperatorBracket: stability tweak

The $allowed tokens array is joined after declaration with the Tokens::$operators array. This is only reliable if the keys in both arrays are unique (or intended to be overwritten).
However, with the $allowed array being numerically indexed and PHP native tokens also being integers, this was not the case and could lead to one of the tokens in the original array (unintentionally) being disregarded/overwritten by one of the tokens in the Tokens::$operators array.

Fixed now, by making setting the tokens constants both as the key as well as the value, making the entries in the array suitable for an array join operation.

Suggested changelog entry

N/A

jrfnl added 2 commits April 7, 2025 01:01
The `%` modulus token is included in the `Tokens::$operators` array. No need to add it separately.
The `$allowed` tokens array is joined after declaration with the `Tokens::$operators` array. This is only reliable if the keys in both arrays are unique (or intended to be overwritten).
However, with the `$allowed` array being numerically indexed and PHP native tokens also being integers, this was not the case and could lead to one of the tokens in the original array (unintentionally) being disregarded/overwritten by one of the tokens in the `Tokens::$operators` array.

Fixed now, by making setting the tokens constants both as the key as well as the value, making the entries in the array suitable for an array join operation.
@jrfnl jrfnl added this to the 3.12.2 milestone Apr 6, 2025
@jrfnl jrfnl merged commit 8dce54e into master Apr 7, 2025
167 of 169 checks passed
@jrfnl jrfnl deleted the feature/squiz-operatorbrackets-minor-simplification branch April 7, 2025 15:42
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