1 | <?php |
||
23 | class RulesResolver extends BaseRules implements ResolverInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var Mapping |
||
27 | */ |
||
28 | private $map; |
||
29 | |||
30 | /** |
||
31 | * RulesResolver constructor. |
||
32 | * @param Mapping $map |
||
33 | */ |
||
34 | public function __construct(Mapping $map) |
||
38 | |||
39 | /** |
||
40 | * @param Readable $readable |
||
41 | * @param RuleInterface|RuleDelegate $rule |
||
42 | * @throws \LogicException |
||
43 | */ |
||
44 | public function resolve(Readable $readable, RuleInterface $rule): void |
||
50 | |||
51 | /** |
||
52 | * @throws ExternalFileException |
||
53 | */ |
||
54 | protected function build(): void |
||
71 | } |
||
72 | |||
73 |
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: