Refactor and clean up reference variables #187
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.