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 | 22 | 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) |
|
97 | |||
98 | /** |
||
99 | * Saves the relation foreign key upon entity add |
||
100 | * |
||
101 | * @param EntityAdded $event |
||
102 | */ |
||
103 | 2 | public function add(EntityAdded $event) |
|
115 | |||
116 | /** |
||
117 | * Gets the relation conditions |
||
118 | * |
||
119 | * @param EntityInterface $entity |
||
120 | * @return array |
||
121 | */ |
||
122 | 2 | protected function getConditions(EntityInterface $entity) |
|
133 | |||
134 | /** |
||
135 | * Gets the foreign key field name |
||
136 | * |
||
137 | * @return string |
||
138 | */ |
||
139 | 6 | View Code Duplication | public function getForeignKey() |
148 | |||
149 | /** |
||
150 | * Check custom conditions |
||
151 | * |
||
152 | * @param Sql\Select $query |
||
153 | * |
||
154 | * @return self |
||
155 | */ |
||
156 | 2 | protected function checkConditions(Sql\Select $query) |
|
163 | |||
164 | /** |
||
165 | * Check custom order |
||
166 | * |
||
167 | * @param Sql\Select $query |
||
168 | * @return self |
||
169 | */ |
||
170 | 2 | protected function checkOrder(Sql\Select $query) |
|
180 | } |
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: