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