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 |
||
15 | class Configuration |
||
16 | { |
||
17 | const DEFAULT_SETTINGS = 'analyze.yml'; |
||
18 | |||
19 | const CONFIG_RULES_KEY = 'rules'; |
||
20 | |||
21 | private $startUri; |
||
22 | |||
23 | private $rules = []; |
||
24 | |||
25 | private $configArray; |
||
26 | |||
27 | private $eventDispatcher; |
||
28 | |||
29 | private $extensions = array(); |
||
30 | |||
31 | private $runLevels = array(); |
||
32 | |||
33 | /** |
||
34 | * @var SessionContainer |
||
35 | */ |
||
36 | private $sessionContainer; |
||
37 | |||
38 | public function __construct(Uri $uri, Dispatcher $eventDispatcher, array $configArray, array $defaultSettings = null) |
||
62 | |||
63 | private function initLogger($loggerArray) |
||
69 | |||
70 | private function initConfigArray(array $configArray, array $defaultSettings = null) |
||
90 | |||
91 | private function initSessionContainer(array $sessionsArray) |
||
107 | |||
108 | private function addListener(array $listenerArray) |
||
116 | |||
117 | /** |
||
118 | * @return Uri |
||
119 | */ |
||
120 | public function getStartUri() |
||
124 | |||
125 | /** |
||
126 | * This function initializes all the rules and sets the log level. |
||
127 | * |
||
128 | * @param array $rulesArray |
||
129 | */ |
||
130 | private function initRules(array $rulesArray) |
||
134 | |||
135 | /** |
||
136 | * Returns the log level of a given rule. |
||
137 | * |
||
138 | * @param string $key |
||
139 | * |
||
140 | * @return int |
||
141 | */ |
||
142 | public function getRuleRunLevel($key) |
||
146 | |||
147 | /** |
||
148 | * @return Rule[] |
||
149 | */ |
||
150 | public function getRules() |
||
154 | |||
155 | public function getSessionContainer() |
||
159 | |||
160 | public function hasSection($section) |
||
164 | |||
165 | /** |
||
166 | * @param $section |
||
167 | * |
||
168 | * @return array |
||
169 | */ |
||
170 | public function getSection($section) |
||
178 | |||
179 | View Code Duplication | public function getExtension($name) |
|
187 | |||
188 | public function addExtension($name, $extension) |
||
193 | |||
194 | public function getConfigArray() |
||
198 | |||
199 | /** |
||
200 | * @return HttpClient |
||
201 | */ |
||
202 | public function getClient() |
||
219 | } |
||
220 |