Skip to content

Commit 0eee691

Browse files
authored
Merge pull request #363 from PHPCSStandards/feature/various-sniff-update-skip-to-end-code
Various sniffs: simplify skipping the rest of the file + update docs about skipping rest of file
2 parents 222548c + dd80edb commit 0eee691

28 files changed

+59
-59
lines changed

src/Sniffs/AbstractScopeSniff.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ final public function register()
123123
*
124124
* @return void|int Optionally returns a stack pointer. The sniff will not be
125125
* called again on the current file until the returned stack
126-
* pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
126+
* pointer is reached. Return `$phpcsFile->numTokens` to skip
127127
* the rest of the file.
128128
* @see processTokenWithinScope()
129129
*/
@@ -164,7 +164,7 @@ final public function process(File $phpcsFile, $stackPtr)
164164
*
165165
* @return void|int Optionally returns a stack pointer. The sniff will not be
166166
* called again on the current file until the returned stack
167-
* pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
167+
* pointer is reached. Return `$phpcsFile->numTokens` to skip
168168
* the rest of the file.
169169
*/
170170
abstract protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope);
@@ -180,7 +180,7 @@ abstract protected function processTokenWithinScope(File $phpcsFile, $stackPtr,
180180
*
181181
* @return void|int Optionally returns a stack pointer. The sniff will not be
182182
* called again on the current file until the returned stack
183-
* pointer is reached. Return (count($tokens) + 1) to skip
183+
* pointer is reached. Return `$phpcsFile->numTokens` to skip
184184
* the rest of the file.
185185
*/
186186
abstract protected function processTokenOutsideScope(File $phpcsFile, $stackPtr);

src/Sniffs/AbstractVariableSniff.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function __construct()
7272
*
7373
* @return void|int Optionally returns a stack pointer. The sniff will not be
7474
* called again on the current file until the returned stack
75-
* pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
75+
* pointer is reached. Return `$phpcsFile->numTokens` to skip
7676
* the rest of the file.
7777
*/
7878
final protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
@@ -156,7 +156,7 @@ final protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $cu
156156
*
157157
* @return void|int Optionally returns a stack pointer. The sniff will not be
158158
* called again on the current file until the returned stack
159-
* pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
159+
* pointer is reached. Return `$phpcsFile->numTokens` to skip
160160
* the rest of the file.
161161
*/
162162
final protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
@@ -187,7 +187,7 @@ final protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
187187
*
188188
* @return void|int Optionally returns a stack pointer. The sniff will not be
189189
* called again on the current file until the returned stack
190-
* pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
190+
* pointer is reached. Return `$phpcsFile->numTokens` to skip
191191
* the rest of the file.
192192
*/
193193
abstract protected function processMemberVar(File $phpcsFile, $stackPtr);
@@ -202,7 +202,7 @@ abstract protected function processMemberVar(File $phpcsFile, $stackPtr);
202202
*
203203
* @return void|int Optionally returns a stack pointer. The sniff will not be
204204
* called again on the current file until the returned stack
205-
* pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
205+
* pointer is reached. Return `$phpcsFile->numTokens` to skip
206206
* the rest of the file.
207207
*/
208208
abstract protected function processVariable(File $phpcsFile, $stackPtr);
@@ -221,7 +221,7 @@ abstract protected function processVariable(File $phpcsFile, $stackPtr);
221221
*
222222
* @return void|int Optionally returns a stack pointer. The sniff will not be
223223
* called again on the current file until the returned stack
224-
* pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
224+
* pointer is reached. Return `$phpcsFile->numTokens` to skip
225225
* the rest of the file.
226226
*/
227227
abstract protected function processVariableInString(File $phpcsFile, $stackPtr);

src/Sniffs/Sniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function register();
7171
*
7272
* @return void|int Optionally returns a stack pointer. The sniff will not be
7373
* called again on the current file until the returned stack
74-
* pointer is reached. Return (count($tokens) + 1) to skip
74+
* pointer is reached. Return `$phpcsFile->numTokens` to skip
7575
* the rest of the file.
7676
*/
7777
public function process(File $phpcsFile, $stackPtr);

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

0 commit comments

Comments
 (0)