Conditions | 15 |
Paths | 128 |
Total Lines | 58 |
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 |
||
90 | public function lint($files = [], $cache = true) |
||
91 | { |
||
92 | if (empty($files)) { |
||
93 | $files = $this->getFiles(); |
||
94 | } |
||
95 | |||
96 | $processCallback = is_callable($this->processCallback) ? $this->processCallback : function () { |
||
97 | }; |
||
98 | |||
99 | $errors = []; |
||
100 | $running = []; |
||
101 | $newCache = []; |
||
102 | |||
103 | while (!empty($files) || !empty($running)) { |
||
104 | for ($i = count($running); !empty($files) && $i < $this->processLimit; ++$i) { |
||
105 | $file = array_shift($files); |
||
106 | $filename = $file->getRealPath(); |
||
107 | $relativePathname = $file->getRelativePathname(); |
||
108 | if (!isset($this->cache[$relativePathname]) || $this->cache[$relativePathname] !== md5_file($filename)) { |
||
109 | $lint = $this->createLintProcess($filename); |
||
110 | $running[$filename] = [ |
||
111 | 'process' => $lint, |
||
112 | 'file' => $file, |
||
113 | 'relativePath' => $relativePathname, |
||
114 | ]; |
||
115 | $lint->start(); |
||
116 | } else { |
||
117 | $newCache[$relativePathname] = $this->cache[$relativePathname]; |
||
118 | } |
||
119 | } |
||
120 | |||
121 | foreach ($running as $filename => $item) { |
||
122 | /** @var Lint $lint */ |
||
123 | $lint = $item['process']; |
||
124 | |||
125 | if ($lint->isRunning()) { |
||
126 | continue; |
||
127 | } |
||
128 | |||
129 | unset($running[$filename]); |
||
130 | |||
131 | if ($lint->hasSyntaxError()) { |
||
132 | $processCallback('error', $item['file']); |
||
133 | $errors[$filename] = array_merge(['file' => $filename, 'file_name' => $item['relativePath']], $lint->getSyntaxError()); |
||
134 | } elseif ($this->warning && $lint->hasSyntaxIssue()) { |
||
135 | $processCallback('warning', $item['file']); |
||
136 | $errors[$filename] = array_merge(['file' => $filename, 'file_name' => $item['relativePath']], $lint->getSyntaxIssue()); |
||
137 | } else { |
||
138 | $newCache[$item['relativePath']] = md5_file($filename); |
||
139 | $processCallback('ok', $item['file']); |
||
140 | } |
||
141 | } |
||
142 | } |
||
143 | |||
144 | $cache && Cache::put($newCache); |
||
145 | |||
146 | return $errors; |
||
147 | } |
||
148 | |||
276 |