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 |
||
16 | class ODMConfig extends InjectableConfig |
||
17 | { |
||
18 | use AliasTrait; |
||
19 | |||
20 | /** |
||
21 | * Configuration section. |
||
22 | */ |
||
23 | const CONFIG = 'odm'; |
||
24 | |||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $config = [ |
||
29 | 'default' => '', |
||
30 | 'aliases' => [], |
||
31 | 'databases' => [], |
||
32 | 'schemas' => [ |
||
33 | 'mutators' => [], |
||
34 | 'mutatorAliases' => [] |
||
35 | ] |
||
36 | ]; |
||
37 | |||
38 | /** |
||
39 | * @return string |
||
40 | */ |
||
41 | public function defaultDatabase() |
||
45 | |||
46 | /** |
||
47 | * @param string $database |
||
48 | * @return bool |
||
49 | */ |
||
50 | public function hasDatabase($database) |
||
54 | |||
55 | /** |
||
56 | * Database connection configuration. |
||
57 | * |
||
58 | * @param string $database |
||
59 | * @return array |
||
60 | */ |
||
61 | public function databaseConfig($database) |
||
65 | |||
66 | /** |
||
67 | * Resolve mutator alias. |
||
68 | * |
||
69 | * @param string $mutator |
||
70 | * @return string |
||
71 | */ |
||
72 | View Code Duplication | public function mutatorAlias($mutator) |
|
80 | |||
81 | /** |
||
82 | * Get list of mutators associated with given type. |
||
83 | * |
||
84 | * @param string $type |
||
85 | * @return array |
||
86 | */ |
||
87 | public function getMutators($type) |
||
93 | } |
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.