| Conditions | 14 |
| Paths | 222 |
| Total Lines | 56 |
| 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 |
||
| 144 | public function run() |
||
| 145 | { |
||
| 146 | $this->startProgressIndicator(); |
||
| 147 | $running = []; |
||
| 148 | $queue = $this->processes; |
||
| 149 | $nextTime = time(); |
||
| 150 | while (true) { |
||
| 151 | if (($nextTime <= time()) && !empty($queue)) { |
||
| 152 | $process = array_shift($queue); |
||
| 153 | $process->setIdleTimeout($this->idleTimeout); |
||
| 154 | $process->setTimeout($this->timeout); |
||
| 155 | $process->start(); |
||
| 156 | $this->printTaskInfo($process->getCommandLine()); |
||
| 157 | $running[] = $process; |
||
| 158 | $nextTime = time() + $this->waitInterval; |
||
| 159 | } |
||
| 160 | foreach ($running as $k => $process) { |
||
| 161 | try { |
||
| 162 | $process->checkTimeout(); |
||
| 163 | } catch (ProcessTimedOutException $e) { |
||
| 164 | $this->printTaskWarning("Process timed out for {command}", ['command' => $process->getCommandLine(), '_style' => ['command' => 'fg=white;bg=magenta']]); |
||
| 165 | } |
||
| 166 | if (!$process->isRunning()) { |
||
| 167 | $this->advanceProgressIndicator(); |
||
| 168 | if ($this->isPrinted) { |
||
| 169 | $this->printTaskInfo("Output for {command}:\n\n{output}", ['command' => $process->getCommandLine(), 'output' => $process->getOutput(), '_style' => ['command' => 'fg=white;bg=magenta']]); |
||
| 170 | $errorOutput = $process->getErrorOutput(); |
||
| 171 | if ($errorOutput) { |
||
| 172 | $this->printTaskError(rtrim($errorOutput)); |
||
| 173 | } |
||
| 174 | } |
||
| 175 | unset($running[$k]); |
||
| 176 | } |
||
| 177 | } |
||
| 178 | if (empty($running) && empty($queue)) { |
||
| 179 | break; |
||
| 180 | } |
||
| 181 | usleep(1000); |
||
| 182 | } |
||
| 183 | $this->stopProgressIndicator(); |
||
| 184 | |||
| 185 | $errorMessage = ''; |
||
| 186 | $exitCode = 0; |
||
| 187 | foreach ($this->processes as $p) { |
||
| 188 | if ($p->getExitCode() === 0) { |
||
| 189 | continue; |
||
| 190 | } |
||
| 191 | $errorMessage .= "'" . $p->getCommandLine() . "' exited with code " . $p->getExitCode() . " \n"; |
||
| 192 | $exitCode = max($exitCode, $p->getExitCode()); |
||
| 193 | } |
||
| 194 | if (!$errorMessage) { |
||
| 195 | $this->printTaskSuccess('{process-count} processes finished running', ['process-count' => count($this->processes)]); |
||
| 196 | } |
||
| 197 | |||
| 198 | return new Result($this, $exitCode, $errorMessage, ['time' => $this->getExecutionTime()]); |
||
| 199 | } |
||
| 200 | } |
||
| 201 |