Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VariableAnalysis/Lib/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static function areAnyConditionsAClosure(File $phpcsFile, array $conditio
*/
public static function areAnyConditionsAClass(array $conditions) {
foreach (array_reverse($conditions, true) as $scopePtr => $scopeCode) {
if ($scopeCode === T_CLASS || $scopeCode === T_TRAIT) {
if ($scopeCode === T_CLASS || $scopeCode === T_ANON_CLASS || $scopeCode === T_TRAIT) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ public function testAnonymousClassAllowPropertyDefinitions() {
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
$expectedWarnings = [
17,
38,
];
$this->assertEquals($expectedWarnings, $lines);
$lines = $this->getErrorLineNumbersFromFile($phpcsFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,29 @@ public function sayHelloWorld() {

public function methodWithStaticVar() {
static $myStaticVar; // should trigger unused warning

echo self::$storedHello;
echo static::$storedHello;
}
};
}
}

$anonClass = new class() {
protected $storedHello;
private static $storedHello2;
private $storedHello3;
public $helloOptions = [];
static $aStaticOne;
var $aVarOne;
public function sayHelloWorld() {
echo "hello world";
}

public function methodWithStaticVar() {
static $myStaticVar; // should trigger unused warning

echo self::$storedHello;
echo static::$storedHello;
}
};