1 | <?php |
||
24 | class TypeInvocationBuilder extends BaseBuilder |
||
25 | { |
||
26 | /** |
||
27 | * @param RuleInterface $rule |
||
28 | * @return bool |
||
29 | */ |
||
30 | public function match(RuleInterface $rule): bool |
||
34 | |||
35 | /** |
||
36 | * @param ContextInterface $ctx |
||
37 | * @param RuleInterface $rule |
||
38 | * @return \Generator|ValueInterface |
||
39 | */ |
||
40 | public function reduce(ContextInterface $ctx, RuleInterface $rule): \Generator |
||
51 | } |
||
52 |
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: