sirbrillig / phpcs-variable-analysis

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

Fix nullable constructor promotion detection #321

Closed sirbrillig closed 6 months ago

sirbrillig commented 6 months ago

When trying to detect variables that are constructor promotion (see https://github.com/sirbrillig/phpcs-variable-analysis/pull/266 and https://github.com/sirbrillig/phpcs-variable-analysis/pull/294) we might also have variables that have nullable types. These variables were not being correctly identified as constructor promotion because the token we were examining to see if it was public/private/protected was actually not far enough back and we were instead looking at the ?.

In this diff, we check for and ignore nullable tokens when looking for constructor promotion.

Fixes https://github.com/sirbrillig/phpcs-variable-analysis/issues/320