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 |
||
34 | class LoggerXmlConfiguration implements LoggerConfigurationInterface |
||
35 | { |
||
36 | |||
37 | /** |
||
38 | * Holds the name of the logger |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $name; |
||
42 | |||
43 | /** |
||
44 | * Holds the type of the logger |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $type; |
||
48 | |||
49 | /** |
||
50 | * 'Holds the loggers channel name |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $channel; |
||
54 | |||
55 | /** |
||
56 | * Holds all handlers defined for logger |
||
57 | * @var array |
||
58 | */ |
||
59 | protected $handlers; |
||
60 | |||
61 | /** |
||
62 | * Holds all processors defined for logger |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $processors; |
||
66 | |||
67 | /** |
||
68 | * Constructs config |
||
69 | * |
||
70 | * @param \SimpleXMLElement $node The simple xml element used to build config |
||
71 | */ |
||
72 | View Code Duplication | public function __construct(\SimpleXMLElement $node) |
|
86 | |||
87 | /** |
||
88 | * Returns name |
||
89 | * |
||
90 | * @return string |
||
91 | */ |
||
92 | public function getName() |
||
96 | |||
97 | /** |
||
98 | * Returns type |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | public function getType() |
||
106 | |||
107 | /** |
||
108 | * Returns channel |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | public function getChannel() |
||
116 | |||
117 | /** |
||
118 | * Returns defined handlers for logger |
||
119 | * |
||
120 | * @return array |
||
121 | */ |
||
122 | public function getHandlers() |
||
126 | |||
127 | /** |
||
128 | * Returns defined processors for logger |
||
129 | * |
||
130 | * @return array |
||
131 | */ |
||
132 | public function getProcessors() |
||
136 | |||
137 | /** |
||
138 | * Prepares handlers array for config |
||
139 | * |
||
140 | * @param \SimpleXMLElement $node The xml node to prepare for |
||
141 | * |
||
142 | * @return array |
||
143 | */ |
||
144 | public function prepareHandlers($node) |
||
178 | |||
179 | /** |
||
180 | * Prepares processors array for config |
||
181 | * |
||
182 | * @param \SimpleXMLElement $node The xml node to prepare for |
||
183 | * |
||
184 | * @return array |
||
185 | */ |
||
186 | public function prepareProcessors($node) |
||
196 | } |
||
197 |
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.