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 static function isSupported(): bool |
||
46 | |||
47 | public function concurrency(int $concurrency): self |
||
53 | |||
54 | public function timeout(int $timeout): self |
||
60 | |||
61 | public function autoload(string $autoloader): self |
||
67 | |||
68 | public function sleepTime(int $sleepTime): self |
||
74 | |||
75 | public function notify() |
||
89 | |||
90 | /** |
||
91 | * @param \Spatie\Async\ParallelProcess|callable $process |
||
92 | * |
||
93 | * @return \Spatie\Async\ParallelProcess |
||
94 | */ |
||
95 | public function add($process): ParallelProcess |
||
105 | |||
106 | public function wait(): array |
||
124 | |||
125 | public function putInQueue(ParallelProcess $process) |
||
131 | |||
132 | public function putInProgress(ParallelProcess $process) |
||
142 | |||
143 | public function markAsFinished(ParallelProcess $process) |
||
153 | |||
154 | View Code Duplication | public function markAsTimedOut(ParallelProcess $process) |
|
164 | |||
165 | View Code Duplication | public function markAsFailed(ParallelProcess $process) |
|
175 | |||
176 | public function offsetExists($offset) |
||
182 | |||
183 | public function offsetGet($offset) |
||
187 | |||
188 | public function offsetSet($offset, $value) |
||
192 | |||
193 | public function offsetUnset($offset) |
||
197 | |||
198 | /** |
||
199 | * @return \Spatie\Async\ParallelProcess[] |
||
200 | */ |
||
201 | public function getFinished(): array |
||
205 | |||
206 | /** |
||
207 | * @return \Spatie\Async\ParallelProcess[] |
||
208 | */ |
||
209 | public function getFailed(): array |
||
213 | |||
214 | protected function registerListener() |
||
242 | } |
||
243 |
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.