@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function __construct(array $processes) |
105 | 105 | { |
106 | - $filtered_processes = array_filter($processes, function ($process) { |
|
106 | + $filtered_processes = array_filter($processes, function($process) { |
|
107 | 107 | return ($process instanceof Process) && !$process->isRunning(); |
108 | 108 | }); |
109 | 109 | |
110 | - if ( count($filtered_processes) !== count($processes) ) { |
|
110 | + if (count($filtered_processes) !== count($processes)) { |
|
111 | 111 | throw new \InvalidArgumentException(sprintf( |
112 | 112 | 'The $processes argument must be an array of non-running instances of "%s" class.', |
113 | 113 | '\Symfony\Component\Process\Process' |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function runAll() |
126 | 126 | { |
127 | - foreach ( $this as $process ) { |
|
127 | + foreach ($this as $process) { |
|
128 | 128 | $process->wait(); |
129 | 129 | } |
130 | 130 | } |
@@ -142,13 +142,13 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function addProcess(Process $process, $key = null) |
144 | 144 | { |
145 | - if ( $key === null ) { |
|
145 | + if ($key === null) { |
|
146 | 146 | $this->processes[] = $process; |
147 | 147 | end($this->processes); |
148 | 148 | $this->waitingQueue[] = key($this->processes); |
149 | 149 | } |
150 | 150 | else { |
151 | - if ( !isset($this->processes[$key]) ) { |
|
151 | + if (!isset($this->processes[$key])) { |
|
152 | 152 | $this->processes[$key] = $process; |
153 | 153 | $this->waitingQueue[] = $key; |
154 | 154 | } |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | { |
233 | 233 | $this->key = null; |
234 | 234 | |
235 | - if ( !count($this->waitingQueue) ) { |
|
235 | + if (!count($this->waitingQueue)) { |
|
236 | 236 | return; |
237 | 237 | } |
238 | 238 | |
@@ -243,38 +243,38 @@ discard block |
||
243 | 243 | $executed_index = null; |
244 | 244 | |
245 | 245 | do { |
246 | - foreach ( $this->runningQueue as $index => $process_key ) { |
|
246 | + foreach ($this->runningQueue as $index => $process_key) { |
|
247 | 247 | $process = $this->processes[$process_key]; |
248 | 248 | |
249 | 249 | try { |
250 | - if ( $this->getProcessException($process_key) ) { |
|
250 | + if ($this->getProcessException($process_key)) { |
|
251 | 251 | $executed_index = $index; |
252 | 252 | continue; |
253 | 253 | } |
254 | 254 | |
255 | 255 | $process->checkTimeout(); |
256 | 256 | |
257 | - if ( $process->isTerminated() ) { |
|
258 | - if ( $executed_index === null ) { |
|
257 | + if ($process->isTerminated()) { |
|
258 | + if ($executed_index === null) { |
|
259 | 259 | $executed_index = $index; |
260 | 260 | } |
261 | 261 | |
262 | 262 | continue; |
263 | 263 | } |
264 | 264 | } |
265 | - catch ( \Exception $exception ) { |
|
265 | + catch (\Exception $exception) { |
|
266 | 266 | $this->setProcessException($process_key, $exception); |
267 | 267 | $executed_index = $index; |
268 | 268 | break; |
269 | 269 | } |
270 | 270 | } |
271 | 271 | |
272 | - if ( $executed_index === null ) { |
|
272 | + if ($executed_index === null) { |
|
273 | 273 | // Check for a setUpdateInterval() timeout. |
274 | - if ( $timeout !== null ) { |
|
274 | + if ($timeout !== null) { |
|
275 | 275 | $elapsed = microtime(true) - $start; |
276 | 276 | |
277 | - if ( $elapsed > $timeout ) { |
|
277 | + if ($elapsed > $timeout) { |
|
278 | 278 | $this->isTimeout = true; |
279 | 279 | |
280 | 280 | return; |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | |
284 | 284 | usleep(1000); |
285 | 285 | } |
286 | - } while ( $executed_index === null ); |
|
286 | + } while ($executed_index === null); |
|
287 | 287 | |
288 | 288 | $this->key = $this->waitingQueue[$executed_index]; |
289 | 289 | unset($this->waitingQueue[$executed_index]); |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | */ |
313 | 313 | public function getProcessException($key = null) |
314 | 314 | { |
315 | - if ( $key === null ) { |
|
315 | + if ($key === null) { |
|
316 | 316 | $key = $this->key(); |
317 | 317 | } |
318 | 318 | |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | */ |
327 | 327 | public function current() |
328 | 328 | { |
329 | - if ( $this->isTimeout ) { |
|
329 | + if ($this->isTimeout) { |
|
330 | 330 | return null; |
331 | 331 | } |
332 | 332 | |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | */ |
341 | 341 | public function key() |
342 | 342 | { |
343 | - if ( $this->isTimeout ) { |
|
343 | + if ($this->isTimeout) { |
|
344 | 344 | return null; |
345 | 345 | } |
346 | 346 | |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | */ |
355 | 355 | public function valid() |
356 | 356 | { |
357 | - if ( $this->isTimeout ) { |
|
357 | + if ($this->isTimeout) { |
|
358 | 358 | return true; |
359 | 359 | } |
360 | 360 | |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | { |
371 | 371 | $old_running_queue = $this->runningQueue; |
372 | 372 | |
373 | - if ( $this->limit ) { |
|
373 | + if ($this->limit) { |
|
374 | 374 | $this->runningQueue = array_slice($this->waitingQueue, 0, $this->limit, true); |
375 | 375 | } |
376 | 376 | else { |
@@ -378,8 +378,8 @@ discard block |
||
378 | 378 | } |
379 | 379 | |
380 | 380 | // Start processes, that were just added to the running queue. |
381 | - foreach ( $this->runningQueue as $index => $process_key ) { |
|
382 | - if ( !isset($old_running_queue[$index]) ) { |
|
381 | + foreach ($this->runningQueue as $index => $process_key) { |
|
382 | + if (!isset($old_running_queue[$index])) { |
|
383 | 383 | $this->processes[$process_key]->start(); |
384 | 384 | } |
385 | 385 | } |
@@ -146,13 +146,11 @@ discard block |
||
146 | 146 | $this->processes[] = $process; |
147 | 147 | end($this->processes); |
148 | 148 | $this->waitingQueue[] = key($this->processes); |
149 | - } |
|
150 | - else { |
|
149 | + } else { |
|
151 | 150 | if ( !isset($this->processes[$key]) ) { |
152 | 151 | $this->processes[$key] = $process; |
153 | 152 | $this->waitingQueue[] = $key; |
154 | - } |
|
155 | - else { |
|
153 | + } else { |
|
156 | 154 | throw new \InvalidArgumentException('The "' . $key . '" key is already in use.'); |
157 | 155 | } |
158 | 156 | } |
@@ -261,8 +259,7 @@ discard block |
||
261 | 259 | |
262 | 260 | continue; |
263 | 261 | } |
264 | - } |
|
265 | - catch ( \Exception $exception ) { |
|
262 | + } catch ( \Exception $exception ) { |
|
266 | 263 | $this->setProcessException($process_key, $exception); |
267 | 264 | $executed_index = $index; |
268 | 265 | break; |
@@ -372,8 +369,7 @@ discard block |
||
372 | 369 | |
373 | 370 | if ( $this->limit ) { |
374 | 371 | $this->runningQueue = array_slice($this->waitingQueue, 0, $this->limit, true); |
375 | - } |
|
376 | - else { |
|
372 | + } else { |
|
377 | 373 | $this->runningQueue = $this->waitingQueue; |
378 | 374 | } |
379 | 375 |