Skip to content

Commit dd80edb

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 8248dbe commit dd80edb

25 files changed

+50
-50
lines changed

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

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

156156
unset($nextNonEmpty, $start);

src/Standards/Generic/Sniffs/Debug/CSSLintSniff.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function process(File $phpcsFile, $stackPtr)
5252
{
5353
$csslintPath = Config::getExecutablePath('csslint');
5454
if ($csslintPath === null) {
55-
return ($phpcsFile->numTokens + 1);
55+
return $phpcsFile->numTokens;
5656
}
5757

5858
$fileName = $phpcsFile->getFilename();
@@ -61,7 +61,7 @@ public function process(File $phpcsFile, $stackPtr)
6161
exec($cmd, $output, $retval);
6262

6363
if (is_array($output) === false) {
64-
return ($phpcsFile->numTokens + 1);
64+
return $phpcsFile->numTokens;
6565
}
6666

6767
$count = count($output);
@@ -90,7 +90,7 @@ public function process(File $phpcsFile, $stackPtr)
9090
}//end for
9191

9292
// Ignore the rest of the file.
93-
return ($phpcsFile->numTokens + 1);
93+
return $phpcsFile->numTokens;
9494

9595
}//end process()
9696

src/Standards/Generic/Sniffs/Debug/ClosureLinterSniff.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function process(File $phpcsFile, $stackPtr)
6969
{
7070
$lintPath = Config::getExecutablePath('gjslint');
7171
if ($lintPath === null) {
72-
return ($phpcsFile->numTokens + 1);
72+
return $phpcsFile->numTokens;
7373
}
7474

7575
$fileName = $phpcsFile->getFilename();
@@ -79,7 +79,7 @@ public function process(File $phpcsFile, $stackPtr)
7979
exec($cmd, $output, $retval);
8080

8181
if (is_array($output) === false) {
82-
return ($phpcsFile->numTokens + 1);
82+
return $phpcsFile->numTokens;
8383
}
8484

8585
foreach ($output as $finding) {
@@ -111,7 +111,7 @@ public function process(File $phpcsFile, $stackPtr)
111111
}//end foreach
112112

113113
// Ignore the rest of the file.
114-
return ($phpcsFile->numTokens + 1);
114+
return $phpcsFile->numTokens;
115115

116116
}//end process()
117117

src/Standards/Generic/Sniffs/Debug/ESLintSniff.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function process(File $phpcsFile, $stackPtr)
6060
{
6161
$eslintPath = Config::getExecutablePath('eslint');
6262
if ($eslintPath === null) {
63-
return ($phpcsFile->numTokens + 1);
63+
return $phpcsFile->numTokens;
6464
}
6565

6666
$filename = $phpcsFile->getFilename();
@@ -86,13 +86,13 @@ public function process(File $phpcsFile, $stackPtr)
8686

8787
if ($code <= 0) {
8888
// No errors, continue.
89-
return ($phpcsFile->numTokens + 1);
89+
return $phpcsFile->numTokens;
9090
}
9191

9292
$data = json_decode(implode("\n", $stdout));
9393
if (json_last_error() !== JSON_ERROR_NONE) {
9494
// Ignore any errors.
95-
return ($phpcsFile->numTokens + 1);
95+
return $phpcsFile->numTokens;
9696
}
9797

9898
// Data is a list of files, but we only pass a single one.
@@ -107,7 +107,7 @@ public function process(File $phpcsFile, $stackPtr)
107107
}
108108

109109
// Ignore the rest of the file.
110-
return ($phpcsFile->numTokens + 1);
110+
return $phpcsFile->numTokens;
111111

112112
}//end process()
113113

src/Standards/Generic/Sniffs/Debug/JSHintSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function process(File $phpcsFile, $stackPtr)
5555
$rhinoPath = Config::getExecutablePath('rhino');
5656
$jshintPath = Config::getExecutablePath('jshint');
5757
if ($jshintPath === null) {
58-
return ($phpcsFile->numTokens + 1);
58+
return $phpcsFile->numTokens;
5959
}
6060

6161
$fileName = $phpcsFile->getFilename();
@@ -89,7 +89,7 @@ public function process(File $phpcsFile, $stackPtr)
8989
}
9090

9191
// Ignore the rest of the file.
92-
return ($phpcsFile->numTokens + 1);
92+
return $phpcsFile->numTokens;
9393

9494
}//end process()
9595

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

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

7878
// Ignore the rest of the file.
79-
return ($phpcsFile->numTokens + 1);
79+
return $phpcsFile->numTokens;
8080

8181
}//end process()
8282

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

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

8585
// Ignore the rest of the file.
86-
return ($phpcsFile->numTokens + 1);
86+
return $phpcsFile->numTokens;
8787

8888
}//end process()
8989

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
@@ -68,7 +68,7 @@ public function process(File $phpcsFile, $stackPtr)
6868

6969
if ($found === $this->eolChar) {
7070
// Ignore the rest of the file.
71-
return ($phpcsFile->numTokens + 1);
71+
return $phpcsFile->numTokens;
7272
}
7373

7474
// Check for single line files without an EOL. This is a very special
@@ -79,7 +79,7 @@ public function process(File $phpcsFile, $stackPtr)
7979
if ($tokens[$lastToken]['line'] === 1
8080
&& $tokens[$lastToken]['content'] !== "\n"
8181
) {
82-
return ($phpcsFile->numTokens + 1);
82+
return $phpcsFile->numTokens;
8383
}
8484
}
8585

@@ -140,7 +140,7 @@ public function process(File $phpcsFile, $stackPtr)
140140
}//end if
141141

142142
// Ignore the rest of the file.
143-
return ($phpcsFile->numTokens + 1);
143+
return $phpcsFile->numTokens;
144144

145145
}//end process()
146146

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

0 commit comments

Comments
 (0)