1 | <?php |
||
19 | class RelationProcessor extends CriterionProcessor |
||
20 | { |
||
21 | /** |
||
22 | * @var int |
||
23 | */ |
||
24 | private static $relationId = 0; |
||
25 | |||
26 | /** |
||
27 | * @var array|string[] |
||
28 | */ |
||
29 | private $relations = []; |
||
30 | |||
31 | /** |
||
32 | * @param QueryBuilder $builder |
||
33 | * @param CriterionInterface|Relation $with |
||
34 | * @return QueryBuilder |
||
35 | */ |
||
36 | public function apply(QueryBuilder $builder, CriterionInterface $with): QueryBuilder |
||
57 | |||
58 | /** |
||
59 | * @param string $parent |
||
60 | * @return bool |
||
61 | */ |
||
62 | private function hasAlias(string $parent): bool |
||
66 | |||
67 | /** |
||
68 | * @param string $parent |
||
69 | * @param string $class |
||
70 | * @return string |
||
71 | */ |
||
72 | private function fetchAlias(string $parent, string $class): string |
||
80 | |||
81 | /** |
||
82 | * @param string $class |
||
83 | * @return string |
||
84 | */ |
||
85 | private function createAlias(string $class): string |
||
89 | } |
||
90 |
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: