| Conditions | 13 |
| Paths | 100 |
| Total Lines | 46 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 78 | public function lint($files = [], $cache = true) |
||
| 79 | { |
||
| 80 | if (empty($files)) { |
||
| 81 | $files = $this->getFiles(); |
||
| 82 | } |
||
| 83 | |||
| 84 | $processCallback = is_callable($this->processCallback) ? $this->processCallback : function () { |
||
| 85 | }; |
||
| 86 | |||
| 87 | $errors = []; |
||
| 88 | $running = []; |
||
| 89 | $newCache = []; |
||
| 90 | |||
| 91 | while (!empty($files) || !empty($running)) { |
||
| 92 | for ($i = count($running); !empty($files) && $i < $this->procLimit; ++$i) { |
||
| 93 | $file = array_shift($files); |
||
| 94 | $filename = $file->getRealpath(); |
||
| 95 | |||
| 96 | if (!isset($this->cache[$filename]) || $this->cache[$filename] !== md5_file($filename)) { |
||
| 97 | $running[$filename] = new Lint(PHP_BINARY.' -d error_reporting=E_ALL -d display_errors=On -l '.escapeshellarg($filename)); |
||
| 98 | $running[$filename]->start(); |
||
| 99 | } else { |
||
| 100 | $newCache[$filename] = $this->cache[$filename]; |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | foreach ($running as $filename => $lintProcess) { |
||
| 105 | if ($lintProcess->isRunning()) { |
||
| 106 | continue; |
||
| 107 | } |
||
| 108 | |||
| 109 | unset($running[$filename]); |
||
| 110 | if ($lintProcess->hasSyntaxError()) { |
||
| 111 | $processCallback('error', $filename); |
||
| 112 | $errors[$filename] = array_merge(['file' => $filename], $lintProcess->getSyntaxError()); |
||
| 113 | } else { |
||
| 114 | $newCache[$filename] = md5_file($filename); |
||
| 115 | $processCallback('ok', $filename); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | $cache && Cache::put($newCache); |
||
| 120 | } |
||
| 121 | |||
| 122 | return $errors; |
||
| 123 | } |
||
| 124 | |||
| 234 |
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.