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