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:
Complex classes like ReflectionClassFactory often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ReflectionClassFactory, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
9 | class ReflectionClassFactory implements ReflectionFactoryInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var \ReflectionClass |
||
13 | */ |
||
14 | private $reflection; |
||
15 | |||
16 | public function __construct($instance) |
||
26 | |||
27 | public static function create($instance) |
||
31 | |||
32 | public function getConstant($name) |
||
36 | |||
37 | public function getConstants() |
||
41 | |||
42 | public function getConstructor() |
||
46 | |||
47 | public function getDefaultProperties() |
||
51 | |||
52 | public function getDocComment() |
||
56 | |||
57 | public function getEndLine() |
||
61 | |||
62 | public function getExtension() |
||
66 | |||
67 | public function getExtensionName() |
||
71 | |||
72 | public function getFileName() |
||
76 | |||
77 | public function getInterfaceNames() |
||
81 | |||
82 | public function getInterfaces() |
||
86 | |||
87 | public function getMethod($name) |
||
91 | |||
92 | public function getMethods() |
||
96 | |||
97 | public function getModifiers() |
||
101 | |||
102 | public function getName() |
||
106 | |||
107 | public function getNamespaceName() |
||
111 | |||
112 | public function getParentClass() |
||
116 | |||
117 | public function getProperties($filter = null) |
||
123 | |||
124 | public function getProperty($name) |
||
128 | |||
129 | public function getShortName() |
||
133 | |||
134 | public function getStartLine() |
||
138 | |||
139 | public function getStaticProperties() |
||
143 | |||
144 | public function getStaticPropertyValue($name, &$def_value = null) |
||
150 | |||
151 | public function getTraitAliases() |
||
155 | |||
156 | public function getTraitNames() |
||
160 | |||
161 | public function getTraits() |
||
165 | |||
166 | View Code Duplication | public function hasConstant($name) |
|
176 | |||
177 | View Code Duplication | public function hasMethod($name) |
|
187 | |||
188 | View Code Duplication | public function hasProperty($name) |
|
198 | |||
199 | View Code Duplication | public function implementsInterface($interface) |
|
209 | |||
210 | public function inNamespace() |
||
214 | |||
215 | public function isAbstract() |
||
219 | |||
220 | public function isCloneable() |
||
224 | |||
225 | public function isFinal() |
||
229 | |||
230 | public function isInstance($object) |
||
240 | |||
241 | public function isInstantiable() |
||
245 | |||
246 | public function isInterface() |
||
250 | |||
251 | public function isInternal() |
||
255 | |||
256 | public function isIterateable() |
||
260 | |||
261 | View Code Duplication | public function isSubclassOf($class) |
|
271 | |||
272 | public function isTrait() |
||
276 | |||
277 | public function isUserDefined() |
||
281 | |||
282 | public function newInstance() |
||
286 | |||
287 | public function newInstanceArgs($args) |
||
297 | |||
298 | public function newInstanceWithoutConstructor() |
||
302 | |||
303 | public function setStaticPropertyValue($name, $value) |
||
319 | |||
320 | public function __toString() |
||
324 | |||
325 | public function getReflector() |
||
329 | } |
||
330 |