Conditions | 4 |
Paths | 4 |
Total Lines | 20 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php declare(strict_types = 1); |
||
34 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
35 | { |
||
36 | $tokens = $phpcsFile->getTokens(); |
||
37 | $token = $tokens[$stackPtr]; |
||
38 | $functionNameToken = $tokens[$stackPtr + 2]; |
||
39 | $functionName = $functionNameToken['content']; |
||
40 | if ($functionName !== '__construct') { |
||
41 | return; |
||
42 | } |
||
43 | |||
44 | $startIndex = $token['scope_opener']; |
||
45 | $endIndex = $token['scope_closer']; |
||
46 | |||
47 | for ($index=$startIndex; $index <= $endIndex; $index++) { |
||
48 | if (in_array($tokens[$index]['type'], $this->loops)) { |
||
49 | $phpcsFile->addError("Class constructor cannot contain a loop.", $stackPtr); |
||
50 | continue; |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 | } |
||
55 |