Description
Hey,
phpcs: PHP_CodeSniffer version 3.4.1 (stable) by Squiz (http://www.squiz.net)
sirbrillig/phpcs-variable-analysis: v2.6.0
It looks like anonymous classed aren't fully supported.
I did notice this issue: #52 which is referenced in this pr: https://github.com/sirbrillig/phpcs-variable-analysis/pull/53/files
Both changes in VariableAnalysis/Lib/Helpers.php
and VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
are in my local installation.
However, this heavily simplified file:
<?php
declare(strict_types=1);
namespace Test;
class Test {
public function getTest() {
return new class() {
protected $property;
public function __construct() {
$this->property = 'my-property';
}
public function getProperty() {
return $this->property;
}
};
}
}
Shows the following error: 13 | WARNING | Variable $property is undefined.
A var_export($token)
on vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Lib/Helpers.php:196
shows:
array (
'code' => 320,
'type' => 'T_VARIABLE',
'content' => '$property',
'line' => 13,
'column' => 23,
'length' => 9,
'level' => 3,
'conditions' =>
array (
16 => 361,
25 => 346,
39 => 'PHPCS_T_ANON_CLASS',
),
)
I'm not that knowledgable about the inner workings of the code sniffer, but maybe you can reproduce the issue and possibly fix it?
Thanks anyway!