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); |
||
7 | class ExplainCommandBuilder |
||
8 | { |
||
9 | /** |
||
10 | * @param Query $query |
||
11 | * @param string $verbosity |
||
12 | * |
||
13 | * @return array |
||
14 | * @throws \Exception |
||
15 | */ |
||
16 | 11 | public static function createCommandArgs( |
|
43 | |||
44 | /** |
||
45 | * @param Query $query |
||
46 | * @param $args |
||
47 | * |
||
48 | * @return array |
||
49 | */ |
||
50 | 10 | private static function manageCount(Query $query, array $args): array |
|
64 | |||
65 | /** |
||
66 | * @param Query $query |
||
67 | * @param $args |
||
68 | * |
||
69 | * @return array |
||
70 | */ |
||
71 | 10 | private static function manageDistinct(Query $query, array $args): array |
|
82 | |||
83 | /** |
||
84 | * @param Query $query |
||
85 | * @param array $args |
||
86 | * |
||
87 | * @return array |
||
88 | */ |
||
89 | 10 | private static function manageFind(Query $query, array $args): array |
|
104 | |||
105 | /** |
||
106 | * @param Query $query |
||
107 | * @param array $args |
||
108 | * |
||
109 | * @return array |
||
110 | */ |
||
111 | 10 | private static function manageDelete(Query $query, array $args): array |
|
124 | } |
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.