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 | public static function getPuliFactory() |
||
45 | |||
46 | /** |
||
47 | * Sets the Puli factory. |
||
48 | * |
||
49 | * @param object $puliFactory |
||
50 | */ |
||
51 | public static function setPuliFactory($puliFactory) |
||
60 | |||
61 | /** |
||
62 | * Resets the factory. |
||
63 | */ |
||
64 | public static function resetPuliFactory() |
||
69 | |||
70 | /** |
||
71 | * Returns the Puli discovery layer. |
||
72 | * |
||
73 | * @return Discovery |
||
74 | */ |
||
75 | public static function getPuliDiscovery() |
||
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | public static function find($type) |
||
105 | } |
||
106 |
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: