Conditions | 4 |
Paths | 6 |
Total Lines | 22 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php declare(strict_types = 1); |
||
27 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
28 | { |
||
29 | $tokens = $phpcsFile->getTokens(); |
||
30 | $endOfMethodIndex = $tokens[$stackPtr]['scope_closer']; |
||
31 | $endOfMethodLine = $tokens[$endOfMethodIndex]['line']; |
||
32 | |||
33 | $nextCodeLine = 0; |
||
34 | for ($index=$endOfMethodIndex + 1; $index <= count($tokens); $index++) { |
||
|
|||
35 | $currentToken = $tokens[$index]; |
||
36 | if ($currentToken['type'] == 'T_WHITESPACE') { |
||
37 | continue; |
||
38 | } |
||
39 | $nextCodeLine = $currentToken['line']; |
||
40 | break; |
||
41 | } |
||
42 | |||
43 | $linesBetween = $nextCodeLine - $endOfMethodLine - 1; |
||
44 | |||
45 | if ($linesBetween > 1) { |
||
46 | $phpcsFile->addError("No more than 1 line after a method/function is allowed.", $stackPtr); |
||
47 | } |
||
48 | } |
||
49 | } |
||
50 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: