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 |
||
26 | View Code Duplication | class LogChannel extends Response |
|
|
|||
27 | { |
||
28 | /** |
||
29 | * @var string The log channel path |
||
30 | */ |
||
31 | private $channel; |
||
32 | |||
33 | /** |
||
34 | * @var string The various log levels |
||
35 | */ |
||
36 | private $configuration; |
||
37 | |||
38 | /** |
||
39 | * @var string Whether or not a log type is enabled |
||
40 | */ |
||
41 | private $status; |
||
42 | |||
43 | /** |
||
44 | * @var string Types of logs for the log channel |
||
45 | */ |
||
46 | private $type; |
||
47 | |||
48 | /** |
||
49 | * @return string The log channel path |
||
50 | */ |
||
51 | public function getChannel() |
||
55 | |||
56 | /** |
||
57 | * @return string The various log levels |
||
58 | */ |
||
59 | public function getConfiguration() |
||
63 | |||
64 | /** |
||
65 | * @return string Whether or not a log type is enabled |
||
66 | */ |
||
67 | public function getStatus() |
||
71 | |||
72 | /** |
||
73 | * @return string Types of logs for the log channel |
||
74 | */ |
||
75 | public function getType() |
||
79 | |||
80 | /** |
||
81 | * @param string $response |
||
82 | */ |
||
83 | public function __construct($response) |
||
92 | |||
93 | } |
||
94 |
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.