| Conditions | 10 |
| Paths | 35 |
| Total Lines | 67 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 70 | function handleFiles(Iterator $regexIterator, string $baseFolder): array |
||
| 71 | { |
||
| 72 | $codes = []; |
||
| 73 | |||
| 74 | foreach ($regexIterator as $file) { |
||
| 75 | [$file] = $file; |
||
| 76 | |||
| 77 | $simpleClassName = str_replace([$baseFolder . DIRECTORY_SEPARATOR, '.php', 'Sniff'], '', $file); |
||
| 78 | $fullQualifiedClassName = 'BestIt\\Sniffs\\' . str_replace('/', '\\', $simpleClassName) . 'Sniff'; |
||
| 79 | |||
| 80 | $hasSuppresses = (bool) preg_match_all( |
||
| 81 | '/->isSniffSuppressed\((?P<code>\s*.*\s*)\)/mU', |
||
| 82 | file_get_contents($file), |
||
| 83 | $suppresses |
||
| 84 | ); |
||
| 85 | |||
| 86 | try { |
||
| 87 | $constants = getConstants($fullQualifiedClassName); |
||
| 88 | |||
| 89 | foreach ($constants as $constant => $constantValue) { |
||
| 90 | if (substr($constant, 0, 5) === 'CODE_') { |
||
| 91 | $sniffDesc = getCodeDesc($fullQualifiedClassName, $constant); |
||
| 92 | |||
| 93 | $sniffRule = sprintf( |
||
| 94 | 'BestIt.%s.%s', |
||
| 95 | str_replace(DIRECTORY_SEPARATOR, '.', $simpleClassName), |
||
| 96 | $constantValue |
||
| 97 | ); |
||
| 98 | |||
| 99 | $codes[$sniffRule] = [$sniffDesc, $hasSuppresses]; |
||
| 100 | |||
| 101 | if ($hasSuppresses) { |
||
| 102 | if (!array_filter($suppresses['code'])) { |
||
| 103 | $codes[$sniffRule][1] = 'yes by class'; |
||
| 104 | } else { |
||
| 105 | $codeHasMatchingSuppress = false; |
||
| 106 | |||
| 107 | foreach ($suppresses['code'] as $foundSuppress) { |
||
| 108 | $foundSuppressValue = str_replace(['self::', 'static::'], '', $foundSuppress); |
||
| 109 | |||
| 110 | |||
| 111 | if ( |
||
| 112 | $codeHasMatchingSuppress = in_array( |
||
| 113 | $foundSuppressValue, |
||
| 114 | [$constant, $constantValue], |
||
| 115 | true |
||
| 116 | ) |
||
| 117 | ) { |
||
| 118 | $codes[$sniffRule][1] = 'yes'; |
||
| 119 | |||
| 120 | break; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | if (!$codeHasMatchingSuppress) { |
||
| 125 | $codes[$sniffRule][1] = false; |
||
| 126 | } |
||
| 127 | } |
||
| 128 | } |
||
| 129 | } |
||
| 130 | } |
||
| 131 | } catch (ReflectionException $e) { |
||
| 132 | echo $e; |
||
| 133 | } |
||
| 134 | } |
||
| 135 | return $codes; |
||
| 136 | } |
||
| 137 | |||
| 174 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.