1 | <?php |
||
23 | class TypeDefinitionBuilder extends BaseBuilder |
||
24 | { |
||
25 | /** |
||
26 | * @param RuleInterface $rule |
||
27 | * @return bool |
||
28 | */ |
||
29 | public function match(RuleInterface $rule): bool |
||
33 | |||
34 | /** |
||
35 | * @param ContextInterface $ctx |
||
36 | * @param RuleInterface $rule |
||
37 | * @return \Generator|Definition |
||
38 | * @throws InvalidArgumentException |
||
39 | */ |
||
40 | public function reduce(ContextInterface $ctx, RuleInterface $rule): \Generator |
||
56 | |||
57 | /** |
||
58 | * @param RuleInterface $argument |
||
59 | * @return \Generator|TypeNameInterface |
||
60 | */ |
||
61 | private function getArgumentName(RuleInterface $argument): \Generator |
||
66 | |||
67 | /** |
||
68 | * @param RuleInterface $argument |
||
69 | * @return \Generator|TypeNameInterface |
||
70 | */ |
||
71 | private function getArgumentValue(RuleInterface $argument): \Generator |
||
76 | } |
||
77 |
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: