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 Reflexion 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 Reflexion, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class Reflexion{ |
||
| 15 | public static function getProperties($instance){ |
||
| 23 | |||
| 24 | public static function getMethods($instance,$filter=null){ |
||
| 32 | |||
| 33 | public static function getKeyFields($instance){ |
||
| 36 | |||
| 37 | public static function getMemberValue($instance,$member){ |
||
| 42 | |||
| 43 | public static function getProperty($instance,$member){ |
||
| 48 | |||
| 49 | public static function getPropertiesAndValues($instance,$props=NULL){ |
||
| 66 | |||
| 67 | public static function getAnnotationClass($class,$annotation){ |
||
| 71 | |||
| 72 | public static function getAnnotationMember($class,$member,$annotation){ |
||
| 78 | |||
| 79 | public static function getAnnotationsMethod($class,$method,$annotation){ |
||
| 85 | |||
| 86 | public static function getMembersAnnotationWithAnnotation($class,$annotation){ |
||
| 96 | |||
| 97 | View Code Duplication | public static function getMembersWithAnnotation($class,$annotation){ |
|
| 107 | |||
| 108 | View Code Duplication | public static function getMembersNameWithAnnotation($class,$annotation){ |
|
| 118 | |||
| 119 | public static function isNullable($class,$member){ |
||
| 126 | |||
| 127 | public static function isSerializable($class,$member){ |
||
| 134 | |||
| 135 | View Code Duplication | public static function getFieldName($class,$member){ |
|
| 143 | |||
| 144 | public static function getTableName($class){ |
||
| 157 | } |
||
| 158 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.