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 | /** |
||
| 14 | * @param array $data |
||
| 15 | * @param array $result |
||
| 16 | */ |
||
| 17 | protected function hydrateRowData(array $data, array &$result) |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param string $className |
||
| 28 | * @param array $data |
||
| 29 | * @return object |
||
| 30 | * @throws \Exception |
||
| 31 | */ |
||
| 32 | protected function doHydrateRowData($className, array $data) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @param ClassMetadata $classMetaData |
||
| 78 | * @param array $data |
||
| 79 | * @return mixed |
||
| 80 | * @throws \Exception |
||
| 81 | */ |
||
| 82 | protected function createEntity(ClassMetadata $classMetaData, array $data) |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @param ClassMetadata $classMetaData |
||
| 93 | * @param array $data |
||
| 94 | * @return string |
||
| 95 | * @throws \Exception |
||
| 96 | */ |
||
| 97 | protected function getEntityClassName(ClassMetadata $classMetaData, array $data) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @param array $mapping |
||
| 121 | * @param array $data |
||
| 122 | * @return ArrayCollection |
||
| 123 | */ |
||
| 124 | protected function hydrateOneToOne(array $mapping, $data) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @param array $mapping |
||
| 131 | * @param array $data |
||
| 132 | * @return ArrayCollection |
||
| 133 | */ |
||
| 134 | View Code Duplication | protected function hydrateOneToMany(array $mapping, $data) |
|
| 143 | |||
| 144 | /** |
||
| 145 | * @param array $mapping |
||
| 146 | * @param array $data |
||
| 147 | * @return ArrayCollection |
||
| 148 | */ |
||
| 149 | protected function hydrateManyToOne(array $mapping, $data) |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @param array $mapping |
||
| 156 | * @param array $data |
||
| 157 | * @return ArrayCollection |
||
| 158 | */ |
||
| 159 | View Code Duplication | protected function hydrateManyToMany(array $mapping, $data) |
|
| 168 | |||
| 169 | /** |
||
| 170 | * @param string $className |
||
| 171 | * @param string $property |
||
| 172 | * @param object $object |
||
| 173 | * @return mixed |
||
| 174 | */ |
||
| 175 | protected function getPrivatePropertyValue($className, $property, $object) |
||
| 185 | } |
||
| 186 |
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.