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 |
||
| 9 | class SimpleObjectHydrator extends ArrayHydrator |
||
| 10 | { |
||
| 11 | const HYDRATOR_NAME = 'simpleObject'; |
||
| 12 | |||
| 13 | /** @var string */ |
||
| 14 | protected $rootClassName; |
||
| 15 | |||
| 16 | protected function prepare() |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param array $data |
||
| 25 | * @param array $result |
||
| 26 | */ |
||
| 27 | protected function hydrateRowData(array $data, array &$result) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @return string |
||
| 37 | */ |
||
| 38 | protected function getRootclassName() |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param string $className |
||
| 52 | * @param array $data |
||
| 53 | * @return object |
||
| 54 | * @throws \Exception |
||
| 55 | */ |
||
| 56 | protected function doHydrateRowData($className, array $data) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @param ClassMetadata $classMetaData |
||
| 105 | * @param array $data |
||
| 106 | * @return mixed |
||
| 107 | * @throws \Exception |
||
| 108 | */ |
||
| 109 | protected function createEntity(ClassMetadata $classMetaData, array $data) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @param ClassMetadata $classMetaData |
||
| 120 | * @param array $data |
||
| 121 | * @return string |
||
| 122 | * @throws \Exception |
||
| 123 | */ |
||
| 124 | protected function getEntityClassName(ClassMetadata $classMetaData, array $data) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @param array $mapping |
||
| 148 | * @param array $data |
||
| 149 | * @return ArrayCollection |
||
| 150 | */ |
||
| 151 | protected function hydrateOneToOne(array $mapping, $data) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @param array $mapping |
||
| 158 | * @param array $data |
||
| 159 | * @return ArrayCollection |
||
| 160 | */ |
||
| 161 | View Code Duplication | protected function hydrateOneToMany(array $mapping, $data) |
|
| 170 | |||
| 171 | /** |
||
| 172 | * @param array $mapping |
||
| 173 | * @param array $data |
||
| 174 | * @return ArrayCollection |
||
| 175 | */ |
||
| 176 | protected function hydrateManyToOne(array $mapping, $data) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @param array $mapping |
||
| 183 | * @param array $data |
||
| 184 | * @return ArrayCollection |
||
| 185 | */ |
||
| 186 | View Code Duplication | protected function hydrateManyToMany(array $mapping, $data) |
|
| 195 | |||
| 196 | /** |
||
| 197 | * @param string $className |
||
| 198 | * @param string $property |
||
| 199 | * @param object $object |
||
| 200 | * @return mixed |
||
| 201 | */ |
||
| 202 | protected function getPrivatePropertyValue($className, $property, $object) |
||
| 212 | } |
||
| 213 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.