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 |
||
11 | class TranslationRelation extends Relation |
||
12 | { |
||
13 | /** |
||
14 | * @var \BBSLab\NovaTranslation\Models\Translation|\Illuminate\Database\Eloquent\Builder |
||
15 | */ |
||
16 | protected $query; |
||
17 | |||
18 | /** |
||
19 | * @var \BBSLab\NovaTranslation\Models\Contracts\IsTranslatable |
||
20 | */ |
||
21 | protected $parent; |
||
22 | |||
23 | /** |
||
24 | * @var \BBSLab\NovaTranslation\Models\Translation |
||
25 | */ |
||
26 | protected $related; |
||
27 | |||
28 | public function __construct(Model $parent) |
||
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | public function addConstraints() |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | public function addEagerConstraints(array $models) |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | public function initRelation(array $models, $relation) |
||
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | public function match(array $models, Collection $results, $relation) |
||
106 | |||
107 | /** |
||
108 | * {@inheritdoc} |
||
109 | */ |
||
110 | public function getResults() |
||
116 | } |
||
117 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: