1 | <?php |
||
20 | class RelationBuilder extends WhereBuilder |
||
21 | { |
||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | private $relations = []; |
||
26 | |||
27 | /** |
||
28 | * @param QueryBuilder $builder |
||
29 | * @param CriterionInterface|Relation $relation |
||
30 | * @return \Generator |
||
31 | */ |
||
32 | public function apply($builder, CriterionInterface $relation): \Generator |
||
50 | |||
51 | /** |
||
52 | * @param QueryBuilder $builder |
||
53 | * @param string $child |
||
54 | * @param string $parent |
||
55 | * @return string |
||
56 | */ |
||
57 | private function join(QueryBuilder $builder, string $child, string $parent): string |
||
67 | } |
||
68 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: