Skip to content

Commit 8a2d1c8

Browse files
committed
Cleanup
1 parent a5dda73 commit 8a2d1c8

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

SlevomatCodingStandard/Sniffs/Variables/UselessVariableSniff.php

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,18 @@ public function process(File $phpcsFile, $returnPointer): void
8282

8383
$functionPointer = $this->findFunctionPointer($phpcsFile, $variablePointer);
8484

85-
if ($this->isReturnedByReference($phpcsFile, $functionPointer)) {
86-
return;
87-
}
85+
if ($functionPointer !== null) {
86+
if ($this->isReturnedByReference($phpcsFile, $functionPointer)) {
87+
return;
88+
}
8889

89-
if ($this->isStaticVariable($phpcsFile, $functionPointer, $variablePointer, $variableName)) {
90-
return;
91-
}
90+
if ($this->isStaticVariable($phpcsFile, $functionPointer, $variablePointer, $variableName)) {
91+
return;
92+
}
9293

93-
if ($this->isFunctionParameter($phpcsFile, $functionPointer, $variableName)) {
94-
return;
94+
if ($this->isFunctionParameter($phpcsFile, $functionPointer, $variableName)) {
95+
return;
96+
}
9597
}
9698

9799
$previousVariablePointer = $this->findPreviousVariablePointer($phpcsFile, $returnPointer, $variableName);
@@ -251,12 +253,8 @@ private function findFunctionPointer(File $phpcsFile, int $pointer): ?int
251253
return null;
252254
}
253255

254-
private function isStaticVariable(File $phpcsFile, ?int $functionPointer, int $variablePointer, string $variableName): bool
256+
private function isStaticVariable(File $phpcsFile, int $functionPointer, int $variablePointer, string $variableName): bool
255257
{
256-
if ($functionPointer === null) {
257-
return false;
258-
}
259-
260258
$tokens = $phpcsFile->getTokens();
261259

262260
for ($i = $tokens[$functionPointer]['scope_opener'] + 1; $i < $variablePointer; $i++) {
@@ -276,12 +274,8 @@ private function isStaticVariable(File $phpcsFile, ?int $functionPointer, int $v
276274
return false;
277275
}
278276

279-
private function isFunctionParameter(File $phpcsFile, ?int $functionPointer, string $variableName): bool
277+
private function isFunctionParameter(File $phpcsFile, int $functionPointer, string $variableName): bool
280278
{
281-
if ($functionPointer === null) {
282-
return false;
283-
}
284-
285279
$tokens = $phpcsFile->getTokens();
286280

287281
for ($i = $tokens[$functionPointer]['parenthesis_opener'] + 1; $i < $tokens[$functionPointer]['parenthesis_closer']; $i++) {
@@ -298,12 +292,8 @@ private function isFunctionParameter(File $phpcsFile, ?int $functionPointer, str
298292
return false;
299293
}
300294

301-
private function isReturnedByReference(File $phpcsFile, ?int $functionPointer): bool
295+
private function isReturnedByReference(File $phpcsFile, int $functionPointer): bool
302296
{
303-
if ($functionPointer === null) {
304-
return false;
305-
}
306-
307297
$tokens = $phpcsFile->getTokens();
308298

309299
$referencePointer = TokenHelper::findNextEffective($phpcsFile, $functionPointer + 1);

0 commit comments

Comments
 (0)