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 |
||
| 12 | class midgard_reflection_property |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var Doctrine\Common\Persistence\Mapping\ClassMetadata |
||
| 16 | */ |
||
| 17 | private $cm; |
||
| 18 | |||
| 19 | 11 | public function __construct($mgdschema_class) |
|
| 29 | |||
| 30 | /** |
||
| 31 | * @param string $property The property name |
||
| 32 | * @param boolean $metadata Check metadata properties instead |
||
| 33 | * @return boolean Indicating existence |
||
| 34 | */ |
||
| 35 | public function property_exists($property, $metadata = false) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Returns field's description, if any |
||
| 45 | * |
||
| 46 | * @param string $property |
||
| 47 | * @return string|NULL |
||
| 48 | */ |
||
| 49 | 1 | public function description($property) |
|
| 57 | |||
| 58 | 9 | public function get_mapping($property) |
|
| 65 | |||
| 66 | /** |
||
| 67 | * Is this field a link or not |
||
| 68 | * |
||
| 69 | * @param string $property |
||
| 70 | * @return boolean |
||
| 71 | */ |
||
| 72 | 7 | public function is_link($property) |
|
| 79 | |||
| 80 | 7 | public function is_special_link($property) |
|
| 88 | |||
| 89 | /** |
||
| 90 | * Returns the classname for the link target |
||
| 91 | * |
||
| 92 | * @param string $property |
||
| 93 | * @return string|NULL |
||
| 94 | */ |
||
| 95 | 7 | View Code Duplication | public function get_link_name($property) |
| 110 | |||
| 111 | /** |
||
| 112 | * Returns the target field name |
||
| 113 | * |
||
| 114 | * @param string $property |
||
| 115 | * @return string|NULL |
||
| 116 | */ |
||
| 117 | 2 | View Code Duplication | public function get_link_target($property) |
| 132 | |||
| 133 | /** |
||
| 134 | * Returns field type constant |
||
| 135 | * |
||
| 136 | * @param string $property |
||
| 137 | * @return integer |
||
| 138 | */ |
||
| 139 | 1 | public function get_midgard_type($property) |
|
| 150 | } |
||
| 151 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: