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 |
||
18 | class Configuration |
||
19 | { |
||
20 | const DEFAULT_SETTINGS = 'analyze.yml'; |
||
21 | |||
22 | const CONFIG_RULES_KEY = 'rules'; |
||
23 | |||
24 | const CACHE_DIR = '/tmp/cache/smoke/'; |
||
25 | |||
26 | private $startUri; |
||
27 | |||
28 | private $rules = []; |
||
29 | |||
30 | private $configArray; |
||
31 | |||
32 | private $eventDispatcher; |
||
33 | |||
34 | private $verbose = false; |
||
35 | |||
36 | private $extensions = array(); |
||
37 | |||
38 | private $runLevels = array(); |
||
39 | |||
40 | /** |
||
41 | * @var SessionContainer |
||
42 | */ |
||
43 | private $sessionContainer; |
||
44 | |||
45 | public function __construct(Uri $uri, Dispatcher $eventDispatcher, array $configArray, array $defaultSettings = null) |
||
70 | |||
71 | private function initCache() |
||
76 | |||
77 | private function initLogger($loggerArray) |
||
83 | |||
84 | private function initConfigArray(array $configArray, array $defaultSettings = null) |
||
108 | |||
109 | private function initSessionContainer(array $sessionsArray) |
||
125 | |||
126 | /** |
||
127 | * @param array $listenerArray |
||
128 | * @throws \phmLabs\Components\Annovent\Exception |
||
129 | */ |
||
130 | private function addListener(array $listenerArray) |
||
138 | |||
139 | /** |
||
140 | * @return Uri |
||
141 | */ |
||
142 | public function getStartUri() |
||
146 | |||
147 | /** |
||
148 | * This function initializes all the rules and sets the log level. |
||
149 | * |
||
150 | * @param array $rulesArray |
||
151 | */ |
||
152 | private function initRules(array $rulesArray) |
||
156 | |||
157 | /** |
||
158 | * Returns the log level of a given rule. |
||
159 | * |
||
160 | * @param string $key |
||
161 | * |
||
162 | * @return int |
||
163 | */ |
||
164 | public function getRuleRunLevel($key) |
||
168 | |||
169 | /** |
||
170 | * @return Rule[] |
||
171 | */ |
||
172 | public function getRules() |
||
176 | |||
177 | public function getSessionContainer() |
||
181 | |||
182 | public function hasSection($section) |
||
186 | |||
187 | /** |
||
188 | * @param $section |
||
189 | * |
||
190 | * @return array |
||
191 | */ |
||
192 | public function getSection($section) |
||
200 | |||
201 | View Code Duplication | public function getExtension($name) |
|
209 | |||
210 | /** |
||
211 | * @param $name |
||
212 | * @param $extension |
||
213 | * @throws \phmLabs\Components\Annovent\Exception |
||
214 | */ |
||
215 | public function addExtension($name, $extension) |
||
220 | |||
221 | public function getConfigArray() |
||
225 | |||
226 | /** |
||
227 | * @return HttpClient |
||
228 | */ |
||
229 | public function getClient() |
||
246 | |||
247 | /** |
||
248 | * @return bool |
||
249 | */ |
||
250 | public function isVerbose(): bool |
||
254 | } |
||
255 |