Conditions | 5 |
Paths | 5 |
Total Lines | 22 |
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 | |||
41 | if ($functionName !== '__construct') { |
||
42 | return; |
||
43 | } |
||
44 | // If this is an interface we don't check it. |
||
45 | if (! isset($token['scope_opener'])) { |
||
46 | return; |
||
47 | } |
||
48 | |||
49 | for ($index=$token['scope_opener']; $index <= $token['scope_closer']; $index++) { |
||
50 | if (in_array($tokens[$index]['type'], $this->loops)) { |
||
51 | $phpcsFile->addError("Class constructor cannot contain a loop.", $stackPtr); |
||
52 | continue; |
||
53 | } |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 |