| Conditions | 13 |
| Paths | 104 |
| Total Lines | 53 |
| 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 |
||
| 81 | public function lint($files = [], $cache = true) |
||
| 82 | { |
||
| 83 | if (empty($files)) { |
||
| 84 | $files = $this->getFiles(); |
||
| 85 | } |
||
| 86 | |||
| 87 | $processCallback = is_callable($this->processCallback) ? $this->processCallback : function () { |
||
| 88 | }; |
||
| 89 | |||
| 90 | $errors = []; |
||
| 91 | $running = []; |
||
| 92 | $newCache = []; |
||
| 93 | |||
| 94 | while (!empty($files) || !empty($running)) { |
||
| 95 | for ($i = count($running); !empty($files) && $i < $this->processLimit; ++$i) { |
||
| 96 | $file = array_shift($files); |
||
| 97 | $filename = $file->getRealPath(); |
||
| 98 | $relativePathname = $file->getRelativePathname(); |
||
| 99 | if (!isset($this->cache[$relativePathname]) || $this->cache[$relativePathname] !== md5_file($filename)) { |
||
| 100 | $lint = $this->createLintProcess($filename); |
||
| 101 | $running[$filename] = [ |
||
| 102 | 'process' => $lint, |
||
| 103 | 'file' => $file, |
||
| 104 | 'relativePath' => $relativePathname, |
||
| 105 | ]; |
||
| 106 | $lint->start(); |
||
| 107 | } else { |
||
| 108 | $newCache[$relativePathname] = $this->cache[$relativePathname]; |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | foreach ($running as $filename => $item) { |
||
| 113 | /** @var Lint $lint */ |
||
| 114 | $lint = $item['process']; |
||
| 115 | if ($lint->isRunning()) { |
||
| 116 | continue; |
||
| 117 | } |
||
| 118 | |||
| 119 | unset($running[$filename]); |
||
| 120 | if ($lint->hasSyntaxError()) { |
||
| 121 | $processCallback('error', $item['file']); |
||
| 122 | $errors[$filename] = array_merge(['file' => $filename], $lint->getSyntaxError()); |
||
| 123 | } else { |
||
| 124 | $newCache[$item['relativePath']] = md5_file($filename); |
||
| 125 | $processCallback('ok', $item['file']); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | $cache && Cache::put($newCache); |
||
| 131 | |||
| 132 | return $errors; |
||
| 133 | } |
||
| 134 | |||
| 261 |