sirbrillig / phpcs-variable-analysis

Find undefined and unused variables with the PHP Codesniffer static analysis tool.
Other
136 stars 14 forks source link

fix: Process variable before the end of scope #324

Closed biinari closed 4 months ago

biinari commented 4 months ago

fixes #323

When the last php code is a short php open echo tag using a variable, process the variable before processing the end of scope.

<?php
$a = 'foo';
?>
<html>
<?= $a ?> the last non-empty token is a variable.
</html>
sirbrillig commented 4 months ago

Thank you! Sorry it took so long to review. I've been AFK for a month.

This is a very elegant fix although I'm not 100% sure I understand how it solves this bug since a token that's a variable shouldn't also be a token that closes a scope, but the tests pass so I'm content.

biinari commented 4 months ago

Thanks for the review @sirbrillig, that was pretty quick to be honest. Hope you had a good break from the keyboard :)

To elaborate on how this fixes the issue, the variable isn't a token that would close a scope. It has just ended up as the last non-empty token in the file, making it the end of the top-level scope.

sirbrillig commented 4 months ago

Ahh, that makes sense. Thanks for clarifying!