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 |
||
26 | class HasMany extends AbstractRelation implements RelationInterface |
||
27 | { |
||
28 | /** |
||
29 | * Relations utility methods |
||
30 | */ |
||
31 | use RelationsUtilityMethods; |
||
32 | |||
33 | /** |
||
34 | * @readwrite |
||
35 | * @var integer |
||
36 | */ |
||
37 | protected $limit; |
||
38 | |||
39 | /** |
||
40 | * @readwrite |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $order; |
||
44 | |||
45 | /** |
||
46 | * @readwrite |
||
47 | * @var mixed |
||
48 | */ |
||
49 | protected $conditions; |
||
50 | |||
51 | /** |
||
52 | * BelongsTo relation |
||
53 | * |
||
54 | * @param array|object $options The parameters from annotation |
||
55 | */ |
||
56 | 20 | public function __construct($options) |
|
69 | |||
70 | /** |
||
71 | * Loads the entity or entity collection for this relation |
||
72 | * |
||
73 | * @param EntityInterface $entity |
||
74 | * |
||
75 | * @return null|EntityInterface|EntityCollection|EntityInterface[] |
||
76 | */ |
||
77 | 2 | public function load(EntityInterface $entity) |
|
92 | |||
93 | /** |
||
94 | * Saves the relation foreign key upon entity add |
||
95 | * |
||
96 | * @param EntityAdded $event |
||
97 | */ |
||
98 | 2 | public function add(EntityAdded $event) |
|
110 | |||
111 | /** |
||
112 | * Gets the relation conditions |
||
113 | * |
||
114 | * @param EntityInterface $entity |
||
115 | * @return array |
||
116 | */ |
||
117 | 2 | protected function getConditions(EntityInterface $entity) |
|
128 | |||
129 | /** |
||
130 | * Gets the foreign key field name |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | 6 | View Code Duplication | public function getForeignKey() |
143 | } |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: