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 |
||
13 | class EmbeddedPropMetadata extends FieldMetadata |
||
14 | { |
||
15 | /** |
||
16 | * The embedded metadata for this embedded property. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | public $embedMeta; |
||
21 | |||
22 | /** |
||
23 | * The embed type: one or many |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | public $embedType; |
||
28 | |||
29 | /** |
||
30 | * Constructor. |
||
31 | * |
||
32 | * @param string $key |
||
33 | * @param string $embedType |
||
34 | * @param EmbedMetadata $embedMeta |
||
35 | * @param bool $mixin |
||
36 | */ |
||
37 | public function __construct($key, $embedType, EmbedMetadata $embedMeta, $mixin = false) |
||
43 | |||
44 | /** |
||
45 | * Determines if this is a one (single) embed. |
||
46 | * |
||
47 | * @return bool |
||
48 | */ |
||
49 | public function isOne() |
||
53 | |||
54 | /** |
||
55 | * Determines if this is a many embed. |
||
56 | * |
||
57 | * @return bool |
||
58 | */ |
||
59 | public function isMany() |
||
63 | |||
64 | /** |
||
65 | * Sets the embed type: one or many. |
||
66 | * |
||
67 | * @param string $relType |
||
68 | * @return self |
||
69 | */ |
||
70 | public function setEmbedType($embedType) |
||
77 | |||
78 | /** |
||
79 | * Validates the embed type. |
||
80 | * |
||
81 | * @param string $type |
||
82 | * @return bool |
||
83 | * @throws MetadataException |
||
84 | */ |
||
85 | View Code Duplication | protected function validateType($embedType) |
|
93 | } |
||
94 |
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..