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); |
||
8 | class ExplainCommandBuilder |
||
9 | { |
||
10 | /** |
||
11 | * @param Query $query |
||
12 | * @param string $verbosity |
||
13 | * |
||
14 | * @return array |
||
15 | * @throws \Exception |
||
16 | */ |
||
17 | public static function createCommandArgs( |
||
57 | |||
58 | /** |
||
59 | * @param Query $query |
||
60 | * |
||
61 | * @return array |
||
62 | */ |
||
63 | private static function getCountArgs(Query $query): array |
||
75 | |||
76 | /** |
||
77 | * @param Query $query |
||
78 | * |
||
79 | * @return array |
||
80 | */ |
||
81 | private static function getFindArgs(Query $query): array |
||
94 | |||
95 | /** |
||
96 | * @param Query $query |
||
97 | * |
||
98 | * @return array |
||
99 | */ |
||
100 | private static function getDistinctArgs(Query $query): array |
||
107 | |||
108 | /** |
||
109 | * @param Query $query |
||
110 | * |
||
111 | * @return array |
||
112 | */ |
||
113 | private static function getDeleteArgs(Query $query): array |
||
122 | } |
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.