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