Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squiz/DisallowMultipleAssignments: bug fix - dynamic property assignment on object stored in array #610

Merged
merged 1 commit into from
Sep 14, 2024

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Sep 8, 2024

Description

The sniff would try to find whether the first "relevant" variable found matches the start of the statement and if not, throw an error, but in the case of dynamic property access on objects stored in an array, the first "relevant" variable determination was off and would get stuck on the ] close bracket of the array access.

Fixed now. Includes ample tests.

This should also make the sniff slightly more efficient for property access code snippets which the sniff already handled correctly.

Suggested changelog entry

Fixed `Squiz.PHP.DisallowMultipleAssignments false positive on assignments to variable property on object stored in array

Related issues/external references

Fixes #598

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Copy link
Contributor

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, and now no violations appear:

Screenshot 2024-09-09 at 15 58 28

…ent on object stored in array

The sniff would try to find whether the first "relevant" variable found matches the start of the statement and if not, throw an error, but in the case of dynamic property access on objects stored in an array, the first "relevant" variable determination was off and would get stuck on the `]` close bracket of the array access.

Fixed now. Includes ample tests.

This should also make the sniff slightly more efficient for property access code snippets which the sniff already handled correctly.

Fixes 598
@jrfnl jrfnl force-pushed the feature/598-squiz-disallowmultipleassignments-bug-fix branch from 5396872 to 0ab692a Compare September 14, 2024 10:05
@jrfnl
Copy link
Member Author

jrfnl commented Sep 14, 2024

Rebased without changes. Merging once the build has passed.

@jrfnl jrfnl merged commit 16b6f35 into master Sep 14, 2024
49 checks passed
@jrfnl jrfnl deleted the feature/598-squiz-disallowmultipleassignments-bug-fix branch September 14, 2024 10:32
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.

DisallowMultipleAssignments false positive when assigning to variable property of an object in an array
2 participants