1 | <?php |
||
14 | class Puli implements DiscoveryStrategy |
||
15 | { |
||
16 | /** |
||
17 | * @var \Puli\GeneratedPuliFactory |
||
18 | */ |
||
19 | private static $puliFactory; |
||
20 | |||
21 | /** |
||
22 | * @var \Puli\Discovery\Api\Discovery |
||
23 | */ |
||
24 | private static $puliDiscovery; |
||
25 | |||
26 | /** |
||
27 | * @return \Puli\GeneratedPuliFactory |
||
28 | * |
||
29 | * @throws PuliUnavailableException |
||
30 | */ |
||
31 | private static function getPuliFactory() |
||
49 | |||
50 | /** |
||
51 | * Returns the Puli discovery layer. |
||
52 | * |
||
53 | * @return \Puli\Discovery\Api\Discovery |
||
54 | * |
||
55 | * @throws PuliUnavailableException |
||
56 | */ |
||
57 | private static function getPuliDiscovery() |
||
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | public static function getCandidates($type) |
||
87 | } |
||
88 |
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: