Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 8 | class Pool implements ArrayAccess |
||
| 9 | { |
||
| 10 | protected $concurrency = 20; |
||
| 11 | protected $tasksPerProcess = 1; |
||
| 12 | protected $timeout = 300; |
||
| 13 | protected $sleepTime = 50000; |
||
| 14 | |||
| 15 | /** @var \Spatie\Async\ParallelProcess[] */ |
||
| 16 | protected $queue = []; |
||
| 17 | |||
| 18 | /** @var \Spatie\Async\ParallelProcess[] */ |
||
| 19 | protected $inProgress = []; |
||
| 20 | |||
| 21 | /** @var \Spatie\Async\ParallelProcess[] */ |
||
| 22 | protected $finished = []; |
||
| 23 | |||
| 24 | /** @var \Spatie\Async\ParallelProcess[] */ |
||
| 25 | protected $failed = []; |
||
| 26 | |||
| 27 | protected $results = []; |
||
| 28 | |||
| 29 | public function __construct() |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @return static |
||
| 36 | */ |
||
| 37 | public static function create() |
||
| 41 | |||
| 42 | public function concurrency(int $concurrency): self |
||
| 48 | |||
| 49 | public function timeout(int $timeout): self |
||
| 55 | |||
| 56 | public function autoload(string $autoloader): self |
||
| 62 | |||
| 63 | public function sleepTime(int $sleepTime): self |
||
| 69 | |||
| 70 | public function notify() |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @param \Spatie\Async\ParallelProcess|callable $process |
||
| 87 | * |
||
| 88 | * @return \Spatie\Async\ParallelProcess |
||
| 89 | */ |
||
| 90 | public function add($process): ParallelProcess |
||
| 100 | |||
| 101 | public function wait(): array |
||
| 119 | |||
| 120 | public function putInQueue(ParallelProcess $process) |
||
| 126 | |||
| 127 | public function putInProgress(ParallelProcess $process) |
||
| 137 | |||
| 138 | public function markAsFinished(ParallelProcess $process) |
||
| 148 | |||
| 149 | View Code Duplication | public function markAsTimedOut(ParallelProcess $process) |
|
| 159 | |||
| 160 | View Code Duplication | public function markAsFailed(ParallelProcess $process) |
|
| 170 | |||
| 171 | public function offsetExists($offset) |
||
| 177 | |||
| 178 | public function offsetGet($offset) |
||
| 182 | |||
| 183 | public function offsetSet($offset, $value) |
||
| 187 | |||
| 188 | public function offsetUnset($offset) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @return \Spatie\Async\ParallelProcess[] |
||
| 195 | */ |
||
| 196 | public function getFinished(): array |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @return \Spatie\Async\ParallelProcess[] |
||
| 203 | */ |
||
| 204 | public function getFailed(): array |
||
| 208 | |||
| 209 | protected function registerListener() |
||
| 237 | } |
||
| 238 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.