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 |
||
11 | final class InjectConfig implements AnnotationInterface |
||
12 | { |
||
13 | /** @var string */ |
||
14 | public $value; |
||
15 | |||
16 | /** @var string */ |
||
17 | public $splitter = '-!splitter-'; |
||
18 | |||
19 | /** |
||
20 | * Get the value. |
||
21 | * |
||
22 | * @param ServiceLocatorInterface $sm |
||
23 | * @return mixed |
||
24 | * |
||
25 | * @throws CannotGetValue |
||
26 | */ |
||
27 | 9 | View Code Duplication | public function getValue(ServiceLocatorInterface $sm) |
35 | |||
36 | /** |
||
37 | * Convert dotted notation to config value. |
||
38 | * |
||
39 | * @param array $config |
||
40 | * @param string $configKey |
||
41 | * @return mixed |
||
42 | */ |
||
43 | 9 | protected function read(array $config, $configKey) |
|
67 | } |
||
68 |