1 | <?php |
||
12 | class Puli implements DiscoveryStrategy |
||
13 | { |
||
14 | /** |
||
15 | * @var GeneratedPuliFactory |
||
16 | */ |
||
17 | private static $puliFactory; |
||
18 | |||
19 | /** |
||
20 | * @var Discovery |
||
21 | */ |
||
22 | private static $puliDiscovery; |
||
23 | |||
24 | /** |
||
25 | * @return GeneratedPuliFactory |
||
26 | * |
||
27 | * @throws PuliUnavailableException |
||
28 | */ |
||
29 | public static function getPuliFactory() |
||
47 | |||
48 | /** |
||
49 | * Sets the Puli factory. |
||
50 | * |
||
51 | * @param object $puliFactory |
||
52 | */ |
||
53 | public static function setPuliFactory($puliFactory) |
||
62 | |||
63 | /** |
||
64 | * Resets the factory. |
||
65 | */ |
||
66 | public static function resetPuliFactory() |
||
71 | |||
72 | /** |
||
73 | * Returns the Puli discovery layer. |
||
74 | * |
||
75 | * @return Discovery |
||
76 | * |
||
77 | * @throws PuliUnavailableException |
||
78 | */ |
||
79 | public static function getPuliDiscovery() |
||
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | public static function find($type) |
||
109 | } |
||
110 |
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: