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 RunnerManager |
||
9 | { |
||
10 | /** @var ContainerInterface */ |
||
11 | private $container; |
||
12 | |||
13 | 7 | public function __construct(ContainerInterface $container) |
|
17 | |||
18 | /** |
||
19 | * @param string|null $group |
||
20 | * |
||
21 | * @return Runner|null |
||
22 | */ |
||
23 | 4 | public function getRunner($group) |
|
29 | |||
30 | /** |
||
31 | * @return array|Runner[] key/value $group/$runner |
||
32 | */ |
||
33 | 1 | View Code Duplication | public function getRunners() |
47 | |||
48 | /** |
||
49 | * @return array|string[] |
||
50 | */ |
||
51 | 1 | View Code Duplication | public function getGroups() |
65 | |||
66 | /** |
||
67 | * @return string |
||
68 | */ |
||
69 | 2 | public function getDefaultGroup() |
|
73 | |||
74 | /** |
||
75 | * @param string|null $group |
||
76 | * |
||
77 | * @return string|null |
||
78 | */ |
||
79 | 4 | private function getRunnerServiceId($group) |
|
89 | |||
90 | /** |
||
91 | * @return array |
||
92 | */ |
||
93 | public function getReporters() |
||
104 | } |
||
105 |
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.