Skip to content

Commit e7875e3

Browse files
committed
UnusedVariableSniff: Fixed false positives
1 parent cc547db commit e7875e3

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

SlevomatCodingStandard/Sniffs/Variables/UnusedVariableSniff.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,18 @@ public function process(File $phpcsFile, $variablePointer): void
8888

8989
$variableName = $tokens[$variablePointer]['content'];
9090

91-
if ($variableName === '$this') {
91+
if (in_array($variableName, [
92+
'$this',
93+
'$GLOBALS',
94+
'$_SERVER',
95+
'$_GET',
96+
'$_POST',
97+
'$_FILES',
98+
'$_COOKIE',
99+
'$_SESSION',
100+
'$_REQUEST',
101+
'$_ENV',
102+
], true)) {
92103
return;
93104
}
94105

tests/Sniffs/Variables/data/unusedVariableNoErrors.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,15 @@ function () {
276276

277277
return $a;
278278
};
279+
280+
function () {
281+
$GLOBALS = [];
282+
$_SERVER = [];
283+
$_GET = [];
284+
$_POST = [];
285+
$_FILES = [];
286+
$_COOKIE = [];
287+
$_SESSION = [];
288+
$_REQUEST = [];
289+
$_ENV = [];
290+
};

0 commit comments

Comments
 (0)