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 |
||
20 | class EntityManager implements EntityManagerInterface { |
||
21 | |||
22 | /** |
||
23 | * The factory container. |
||
24 | * |
||
25 | * @var TheSportsDb\Entity\Factory\FactoryContainerInterface |
||
26 | */ |
||
27 | protected $factoryContainer; |
||
28 | |||
29 | /** |
||
30 | * The repository container. |
||
31 | * |
||
32 | * @var TheSportsDb\Entity\Repository\RepositoryContainerInterface |
||
33 | */ |
||
34 | protected $repositoryContainer; |
||
35 | |||
36 | /** |
||
37 | * Map entity types to classes. |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $classes = array(); |
||
42 | |||
43 | /** |
||
44 | * Property map definitions. |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $propertyMapDefinitions = array(); |
||
49 | |||
50 | /** |
||
51 | * Property map definitions. |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $propertyMaps = array(); |
||
56 | |||
57 | protected $propertyMapper; |
||
58 | |||
59 | |||
60 | const EMPTYPROPERTYPLACEHOLDER = '__EMPTY_PROPERTY_PLACEHOLDER__'; |
||
61 | |||
62 | |||
63 | public function __construct(MapperInterface $propertyMapper, FactoryContainerInterface $factoryContainer = NULL, RepositoryContainerInterface $repositoryContainer = NULL) { |
||
72 | |||
73 | public function setFactoryContainer(FactoryContainerInterface $factoryContainer) { |
||
79 | |||
80 | public function setRepositoryContainer(RepositoryContainerInterface $repositoryContainer) { |
||
86 | |||
87 | |||
88 | /** |
||
89 | * {@inheritdoc} |
||
90 | */ |
||
91 | public function repository($entityType) { |
||
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | public function factory($entityType) { |
||
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | */ |
||
111 | public function registerClass($entityType, $realClass = NULL, $proxyClass = NULL) { |
||
130 | |||
131 | /** |
||
132 | * {@inheritdoc} |
||
133 | */ |
||
134 | public function getPropertyMapDefinition($entityType) { |
||
141 | |||
142 | /** |
||
143 | * {@inheritdoc} |
||
144 | */ |
||
145 | public function getClass($entityType, $type = 'real') { |
||
151 | |||
152 | /** |
||
153 | * {@inheritdoc} |
||
154 | */ |
||
155 | public function mapProperties(\stdClass $values, $entityType) { |
||
165 | |||
166 | |||
167 | /** |
||
168 | * {@inheritdoc} |
||
169 | */ |
||
170 | public function reverseMapProperties(\stdClass $values, $entityType) { |
||
182 | |||
183 | /** |
||
184 | * Initializes the property map. |
||
185 | */ |
||
186 | protected function initPropertyMap($entityType) { |
||
211 | |||
212 | /** |
||
213 | * Gets the property map. |
||
214 | * |
||
215 | * @return FastNorth\PropertyMapper\Map |
||
216 | * The property map. |
||
217 | */ |
||
218 | protected function getPropertyMap($entityType) { |
||
224 | |||
225 | protected function sanitizeObject(\stdClass $object) { |
||
234 | |||
235 | |||
236 | public function isEmptyValue($value) { |
||
239 | } |
||
240 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..