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 declare(strict_types=1); |
||
9 | final class FiniteCaller implements QueueCallerPoolInterface |
||
10 | { |
||
11 | /** @var State */ |
||
12 | private $state; |
||
13 | |||
14 | /** @var QueueCallerInterface[] */ |
||
15 | private $caller = []; |
||
16 | |||
17 | /** @var State[] */ |
||
18 | private $callerState = []; |
||
19 | |||
20 | /** @var Subject */ |
||
21 | private $callerStream = []; |
||
22 | |||
23 | /** @var array */ |
||
24 | private $queue = []; |
||
25 | |||
26 | /** @var int */ |
||
27 | private $callersBusy = 0; |
||
28 | |||
29 | /** @var int */ |
||
30 | private $callersCount = 0; |
||
31 | |||
32 | /** |
||
33 | * @param Kernel $kernel |
||
34 | * @param int $size |
||
35 | */ |
||
36 | 3 | public function __construct(Kernel $kernel, int $size) |
|
69 | |||
70 | 3 | public function call(ObservableInterface $observable): State |
|
78 | |||
79 | 2 | public function info(): iterable |
|
85 | |||
86 | 3 | private function delegateCall(Call $call): void |
|
101 | } |
||
102 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.