Conditions | 6 |
Paths | 7 |
Total Lines | 20 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types = 1); |
||
27 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
28 | { |
||
29 | $tokens = $phpcsFile->getTokens(); |
||
30 | if (! isset($tokens[$stackPtr]['scope_closer'])) { |
||
31 | return; |
||
32 | } |
||
33 | |||
34 | $endOfMethodIndex = $tokens[$stackPtr]['scope_closer']; |
||
35 | $nextCodeLine = 0; |
||
36 | |||
37 | for ($index=$endOfMethodIndex + 1; $index <= count($tokens); $index++) { |
||
|
|||
38 | if (isset($tokens[$index]) && $tokens[$index]['type'] !== 'T_WHITESPACE') { |
||
39 | $nextCodeLine = $tokens[$index]['line']; |
||
40 | break; |
||
41 | } |
||
42 | } |
||
43 | |||
44 | $linesBetween = $nextCodeLine - $tokens[$endOfMethodIndex]['line'] - 1; |
||
45 | if ($linesBetween > 1) { |
||
46 | $phpcsFile->addError("No more than 1 line after a method/function is allowed.", $stackPtr, __CLASS__); |
||
47 | } |
||
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: