Skip to content

Commit 953b513

Browse files
committed
Various sniffs: simplify skipping the rest of the file
This commit updates various sniffs to use `return $phpcsFile->numTokens` instead of `return ($phpcsFile->numTokens + 1)`. If a sniff file contains 50 tokens, the last `$stackPtr` will be 49, so returning `50` will already get us passed the end of the token stack and the `+ 1` is redundant.
1 parent be33885 commit 953b513

File tree

19 files changed

+34
-34
lines changed

19 files changed

+34
-34
lines changed

src/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function process(File $phpcsFile, $stackPtr)
125125
// tag in short open tags and scan run with short_open_tag=Off.
126126
// Bow out completely as any further detection will be unreliable
127127
// and create incorrect fixes or cause fixer conflicts.
128-
return ($phpcsFile->numTokens + 1);
128+
return $phpcsFile->numTokens;
129129
}
130130

131131
unset($nextNonEmpty, $start);

src/Standards/Generic/Sniffs/Files/EndFileNewlineSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function process(File $phpcsFile, $stackPtr)
6565
}
6666

6767
// Ignore the rest of the file.
68-
return ($phpcsFile->numTokens + 1);
68+
return $phpcsFile->numTokens;
6969

7070
}//end process()
7171

src/Standards/Generic/Sniffs/Files/EndFileNoNewlineSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function process(File $phpcsFile, $stackPtr)
7272
}
7373

7474
// Ignore the rest of the file.
75-
return ($phpcsFile->numTokens + 1);
75+
return $phpcsFile->numTokens;
7676

7777
}//end process()
7878

src/Standards/Generic/Sniffs/Files/ExecutableFileSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function process(File $phpcsFile, $stackPtr)
5454
}
5555

5656
// Ignore the rest of the file.
57-
return ($phpcsFile->numTokens + 1);
57+
return $phpcsFile->numTokens;
5858

5959
}//end process()
6060

src/Standards/Generic/Sniffs/Files/LineEndingsSniff.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function process(File $phpcsFile, $stackPtr)
5757

5858
if ($found === $this->eolChar) {
5959
// Ignore the rest of the file.
60-
return ($phpcsFile->numTokens + 1);
60+
return $phpcsFile->numTokens;
6161
}
6262

6363
// Check for single line files without an EOL. This is a very special
@@ -68,7 +68,7 @@ public function process(File $phpcsFile, $stackPtr)
6868
if ($tokens[$lastToken]['line'] === 1
6969
&& $tokens[$lastToken]['content'] !== "\n"
7070
) {
71-
return ($phpcsFile->numTokens + 1);
71+
return $phpcsFile->numTokens;
7272
}
7373
}
7474

@@ -124,7 +124,7 @@ public function process(File $phpcsFile, $stackPtr)
124124
}//end if
125125

126126
// Ignore the rest of the file.
127-
return ($phpcsFile->numTokens + 1);
127+
return $phpcsFile->numTokens;
128128

129129
}//end process()
130130

src/Standards/Generic/Sniffs/Files/LineLengthSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function process(File $phpcsFile, $stackPtr)
8080
$this->checkLineLength($phpcsFile, $tokens, $i);
8181

8282
// Ignore the rest of the file.
83-
return ($phpcsFile->numTokens + 1);
83+
return $phpcsFile->numTokens;
8484

8585
}//end process()
8686

src/Standards/Generic/Sniffs/Files/LowercasedFilenameSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function process(File $phpcsFile, $stackPtr)
4444
{
4545
$filename = $phpcsFile->getFilename();
4646
if ($filename === 'STDIN') {
47-
return ($phpcsFile->numTokens + 1);
47+
return $phpcsFile->numTokens;
4848
}
4949

5050
$filename = basename($filename);
@@ -62,7 +62,7 @@ public function process(File $phpcsFile, $stackPtr)
6262
}
6363

6464
// Ignore the rest of the file.
65-
return ($phpcsFile->numTokens + 1);
65+
return $phpcsFile->numTokens;
6666

6767
}//end process()
6868

src/Standards/Generic/Sniffs/PHP/SyntaxSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function process(File $phpcsFile, $stackPtr)
6767
}
6868

6969
// Ignore the rest of the file.
70-
return ($phpcsFile->numTokens + 1);
70+
return $phpcsFile->numTokens;
7171

7272
}//end process()
7373

src/Standards/Generic/Sniffs/VersionControl/GitMergeConflictSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function process(File $phpcsFile, $stackPtr)
123123
}//end for
124124

125125
// Ignore the rest of the file.
126-
return ($phpcsFile->numTokens + 1);
126+
return $phpcsFile->numTokens;
127127

128128
}//end process()
129129

src/Standards/Generic/Sniffs/VersionControl/SubversionPropertiesSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function process(File $phpcsFile, $stackPtr)
5858
$properties = $this->getProperties($path);
5959
if ($properties === null) {
6060
// Not under version control.
61-
return ($phpcsFile->numTokens + 1);
61+
return $phpcsFile->numTokens;
6262
}
6363

6464
$allProperties = ($properties + $this->properties);
@@ -101,7 +101,7 @@ public function process(File $phpcsFile, $stackPtr)
101101
}//end foreach
102102

103103
// Ignore the rest of the file.
104-
return ($phpcsFile->numTokens + 1);
104+
return $phpcsFile->numTokens;
105105

106106
}//end process()
107107

0 commit comments

Comments
 (0)