1 | <?php |
||
17 | class Puli implements DiscoveryStrategy |
||
18 | { |
||
19 | /** |
||
20 | * @var GeneratedPuliFactory |
||
21 | */ |
||
22 | protected static $puliFactory; |
||
23 | |||
24 | /** |
||
25 | * @var Discovery |
||
26 | */ |
||
27 | protected static $puliDiscovery; |
||
28 | |||
29 | /** |
||
30 | * @return GeneratedPuliFactory |
||
31 | * |
||
32 | * @throws PuliUnavailableException |
||
33 | */ |
||
34 | 2 | private static function getPuliFactory() |
|
52 | |||
53 | /** |
||
54 | * Returns the Puli discovery layer. |
||
55 | * |
||
56 | * @return Discovery |
||
57 | * |
||
58 | * @throws PuliUnavailableException |
||
59 | */ |
||
60 | 2 | private static function getPuliDiscovery() |
|
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | 2 | public static function getCandidates($type) |
|
90 | } |
||
91 |
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: