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 |
||
24 | View Code Duplication | final class Log implements Api |
|
|
|||
25 | { |
||
26 | /** |
||
27 | * Change the logging level. |
||
28 | * |
||
29 | * @Endpoint(name="log:level") |
||
30 | * |
||
31 | * @param string $arg the subsystem logging identifier |
||
32 | * @param string $arg1 the log level, with ‘debug’ the most verbose and ‘critical’ the least verbose |
||
33 | * |
||
34 | * @return Command |
||
35 | */ |
||
36 | public function level(string $arg, string $arg1): Command |
||
40 | |||
41 | /** |
||
42 | * List the logging subsystems. |
||
43 | * |
||
44 | * @Endpoint(name="log:ls") |
||
45 | * |
||
46 | * @return Command |
||
47 | */ |
||
48 | public function ls(): Command |
||
52 | |||
53 | /** |
||
54 | * Read the event log. |
||
55 | * |
||
56 | * @Endpoint(name="log:tail") |
||
57 | * |
||
58 | * @return Command |
||
59 | */ |
||
60 | public function tail(): Command |
||
64 | } |
||
65 |
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.