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 |
||
13 | abstract class AbstractMetadataParser implements MetadataParserInterface |
||
14 | { |
||
15 | /** |
||
16 | * Namespaces for property classes |
||
17 | * |
||
18 | * @var array |
||
19 | */ |
||
20 | private $nsProperty = []; |
||
21 | /** |
||
22 | * Namespaces for structure classes |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | private $nsStruct = []; |
||
27 | /** |
||
28 | * @var MetadataManagerInterface |
||
29 | */ |
||
30 | private $metadataManager; |
||
31 | |||
32 | /** |
||
33 | * Get structure metadata information for given class |
||
34 | * |
||
35 | * @param string $class Structure class name to parse metadata from |
||
36 | * |
||
37 | * @throws Exception |
||
38 | * @return StructMetadata |
||
39 | * @throws \InvalidArgumentException |
||
40 | */ |
||
41 | 182 | public function getMetadata($class) |
|
65 | |||
66 | /** |
||
67 | * @return MetadataManagerInterface |
||
68 | */ |
||
69 | 184 | public function getMetadataManager() |
|
76 | |||
77 | /** |
||
78 | * @param MetadataManagerInterface $metadataManager |
||
79 | */ |
||
80 | 185 | public function setMetadataManager(MetadataManagerInterface $metadataManager) |
|
84 | |||
85 | /** |
||
86 | * Actual implementation of structure metadata parsing |
||
87 | * |
||
88 | * @param \ReflectionClass $reflection |
||
89 | * @param StructMetadata $metadata |
||
90 | * @return void |
||
91 | */ |
||
92 | abstract protected function parseMetadata(\ReflectionClass $reflection, StructMetadata $metadata); |
||
93 | |||
94 | /** |
||
95 | * Resolve given property type into property FQCN |
||
96 | * |
||
97 | * @param string $class Structure property class |
||
98 | * @return string|null |
||
99 | * @throws \InvalidArgumentException |
||
100 | */ |
||
101 | 179 | View Code Duplication | protected function resolvePropertyClass($class) |
109 | |||
110 | /** |
||
111 | * Resolve given class into FQCN class and check if it supports given namespace |
||
112 | * |
||
113 | * @param string $class Class name to resolve |
||
114 | * @param array $namespaces List of namespace to use to expand given class name |
||
115 | * @param string $interface OPTIONAL Interface, class must implement |
||
116 | * @return string|null |
||
117 | */ |
||
118 | 181 | protected function resolveClass($class, array $namespaces, $interface = null) |
|
132 | |||
133 | /** |
||
134 | * Resolve given structure class into structure FQCN |
||
135 | * |
||
136 | * @param string $class Structure class |
||
137 | * @return string|null |
||
138 | * @throws \InvalidArgumentException |
||
139 | */ |
||
140 | 67 | View Code Duplication | protected function resolveStructClass($class) |
148 | } |
||
149 |