Skip to content

Conversation

sirbrillig
Copy link
Owner

@sirbrillig sirbrillig commented Jul 8, 2020

This removes the multiple different ways used to track variable references and instead uses one.

This follows on the work done in #126/#128 and #120 and fixes some edge cases there. Notably, the sniff now treats a local assignment by reference (eg: $foo = &$bar;) as a declaration, not an initialization, since it doesn't really modify the value of anything, it effectively just creates an alias. That means that if the alias is unused, it should be reported as unused (which was already sort-of happening but it was a bit of a hack).

It also means that before we make such an alias, we should check and report if the variable is unused from a previous binding or assignment because after that point, it will effectively be a new variable.

The biggest change in this PR is probably that now every instance of an unused variable counts as a warning, rather than just the first. The reason for this is that if we do not report later instances, if the first instance is ignored (eg: by //phpcs:ignore), the later instances wouldn't be reported at all.

@sirbrillig sirbrillig marked this pull request as ready for review July 8, 2020 21:15
@sirbrillig sirbrillig merged commit c6d3b02 into master Jul 8, 2020
@sirbrillig sirbrillig deleted the clean-up-reference-passing branch July 8, 2020 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant