diff --git a/README.md b/README.md index 4265fa88..43e72fb7 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ Plugin for PHP_CodeSniffer static analysis tool that adds analysis of problematic variable use. - Warns if variables are used without being defined. (Sniff code: `VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable`) -- Warns if variables are used for an array push shortcut without being defined. (Sniff code: `VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedArrayVariable`) - Warns if variables are used inside `unset()` without being defined. (Sniff code: `VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedUnsetVariable`) - Warns if variables are set or declared but never used. (Sniff code: `VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable`) - Warns if `$this`, `self::$static_member`, `static::$static_member` is used outside class scope. (Sniff codes: `VariableAnalysis.CodeAnalysis.VariableAnalysis.SelfOutsideClass` or `VariableAnalysis.CodeAnalysis.VariableAnalysis.StaticOutsideClass`) diff --git a/Tests/VariableAnalysisSniff/ArrayAssignmentShortcutTest.php b/Tests/VariableAnalysisSniff/ArrayAssignmentShortcutTest.php index 8c75c77c..3d28fe50 100644 --- a/Tests/VariableAnalysisSniff/ArrayAssignmentShortcutTest.php +++ b/Tests/VariableAnalysisSniff/ArrayAssignmentShortcutTest.php @@ -25,8 +25,8 @@ public function testArrayAssignmentHasCorrectSniffCodes() { $phpcsFile->process(); $warnings = $phpcsFile->getWarnings(); - $this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedArrayVariable', $warnings[21][5][0]['source']); - $this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedArrayVariable', $warnings[27][5][0]['source']); + $this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[21][5][0]['source']); + $this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[27][5][0]['source']); $this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable', $warnings[28][5][0]['source']); $this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[29][10][0]['source']); } diff --git a/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php b/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php index 87a6e227..4be183da 100644 --- a/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php +++ b/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php @@ -1743,7 +1743,7 @@ protected function warnAboutUndefinedArrayPushShortcut(File $phpcsFile, $varName $phpcsFile->addWarning( "Array variable %s is undefined.", $stackPtr, - 'UndefinedArrayVariable', + 'UndefinedVariable', ["\${$varName}"] ); }