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); |
||
10 | View Code Duplication | final class AddWebHookCommand |
|
|
|||
11 | { |
||
12 | /** |
||
13 | * @var string |
||
14 | */ |
||
15 | private $repository; |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | private $name; |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | private $config; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | private $events; |
||
31 | |||
32 | /** |
||
33 | * @var bool |
||
34 | */ |
||
35 | private $active; |
||
36 | |||
37 | /** |
||
38 | * @param string $repository |
||
39 | * @param string $name |
||
40 | * @param array $config |
||
41 | * @param array $events |
||
42 | * @param bool $active |
||
43 | */ |
||
44 | 1 | public function __construct(string $repository, string $name, array $config, array $events, bool $active) |
|
52 | |||
53 | /** |
||
54 | * @return string |
||
55 | */ |
||
56 | 1 | public function getRepository(): string |
|
60 | |||
61 | /** |
||
62 | * @return string |
||
63 | */ |
||
64 | 1 | public function getName(): string |
|
68 | |||
69 | /** |
||
70 | * @return array |
||
71 | */ |
||
72 | 1 | public function getConfig(): array |
|
76 | |||
77 | /** |
||
78 | * @return array |
||
79 | */ |
||
80 | 1 | public function getEvents(): array |
|
84 | |||
85 | /** |
||
86 | * @return bool |
||
87 | */ |
||
88 | 1 | public function isActive(): bool |
|
92 | } |
||
93 |
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.