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 | View Code Duplication | class GatewayRegistry |
|
1 ignored issue
–
show
|
|||
9 | { |
||
10 | /** |
||
11 | * @var null|GatewayRegistry |
||
12 | */ |
||
13 | private static $instance = null; |
||
14 | |||
15 | /** |
||
16 | * @var Gateway[] |
||
17 | */ |
||
18 | protected $gateways = []; |
||
19 | |||
20 | /** |
||
21 | * @return GatewayRegistry |
||
22 | */ |
||
23 | public static function instance(): GatewayRegistry |
||
31 | |||
32 | /** |
||
33 | * @param string $destinationType |
||
34 | * @param Gateway $gateway |
||
35 | */ |
||
36 | 4 | public function set(string $destinationType, Gateway $gateway): void |
|
40 | |||
41 | /** |
||
42 | * @param array $gateways |
||
43 | */ |
||
44 | public function setAll(array $gateways): void |
||
48 | |||
49 | /** |
||
50 | * @param Destination $destination |
||
51 | * @return Gateway |
||
52 | */ |
||
53 | 5 | public function get(Destination $destination): Gateway |
|
67 | } |
||
68 |
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.