1 | <?php |
||
20 | class RuleDelegate extends Rule implements ProvidesChildrenSymbol |
||
21 | { |
||
22 | /** |
||
23 | * @return string |
||
24 | */ |
||
25 | public function getRuleName(): string |
||
29 | |||
30 | /** |
||
31 | * @return null|string |
||
32 | */ |
||
33 | public function getDelegate(): ?string |
||
39 | |||
40 | /** |
||
41 | * @return RuleInterface|NodeInterface |
||
42 | */ |
||
43 | private function name(): RuleInterface |
||
47 | |||
48 | /** |
||
49 | * @return bool |
||
50 | */ |
||
51 | public function isKept(): bool |
||
55 | |||
56 | /** |
||
57 | * @return iterable |
||
58 | */ |
||
59 | public function getChildrenRules(): iterable |
||
63 | |||
64 | /** |
||
65 | * @return Symbol |
||
66 | */ |
||
67 | public function getRule(): Symbol |
||
71 | |||
72 | /** |
||
73 | * @return ProvidesSymbol|ConcatenationDelegate|NodeInterface |
||
74 | */ |
||
75 | private function getProduction(): ProvidesSymbol |
||
79 | } |
||
80 |
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: