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 |
||
| 23 | class HasMany extends AbstractRelation implements RelationInterface |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * Relations utility methods |
||
| 27 | */ |
||
| 28 | use RelationsUtilityMethods; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @readwrite |
||
| 32 | * @var integer |
||
| 33 | */ |
||
| 34 | protected $limit; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @readwrite |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $order; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @readwrite |
||
| 44 | * @var mixed |
||
| 45 | */ |
||
| 46 | protected $conditions; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * BelongsTo relation |
||
| 50 | * |
||
| 51 | * @param array|object $options The parameters from annotation |
||
| 52 | */ |
||
| 53 | 18 | public function __construct($options) |
|
| 66 | |||
| 67 | /** |
||
| 68 | * Loads the entity or entity collection for this relation |
||
| 69 | * |
||
| 70 | * @param EntityInterface $entity |
||
| 71 | * |
||
| 72 | * @return null|EntityInterface|EntityCollection|EntityInterface[] |
||
| 73 | */ |
||
| 74 | 2 | public function load(EntityInterface $entity) |
|
| 83 | |||
| 84 | /** |
||
| 85 | * Gets the relation conditions |
||
| 86 | * |
||
| 87 | * @param EntityInterface $entity |
||
| 88 | * @return array |
||
| 89 | */ |
||
| 90 | 2 | protected function getConditions(EntityInterface $entity) |
|
| 101 | |||
| 102 | /** |
||
| 103 | * Gets the foreign key field name |
||
| 104 | * |
||
| 105 | * @return string |
||
| 106 | */ |
||
| 107 | 4 | View Code Duplication | public function getForeignKey() |
| 116 | } |
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: