1 | <?php |
||
18 | abstract class ClassDiscovery |
||
19 | { |
||
20 | /** |
||
21 | * @var GeneratedPuliFactory |
||
22 | */ |
||
23 | private static $puliFactory; |
||
24 | |||
25 | /** |
||
26 | * @var Discovery |
||
27 | */ |
||
28 | private static $puliDiscovery; |
||
29 | |||
30 | /** |
||
31 | * @return GeneratedPuliFactory |
||
32 | */ |
||
33 | 10 | public static function getPuliFactory() |
|
51 | |||
52 | /** |
||
53 | * Sets the Puli factory. |
||
54 | * |
||
55 | * @param object $puliFactory |
||
56 | */ |
||
57 | 21 | public static function setPuliFactory($puliFactory) |
|
66 | |||
67 | /** |
||
68 | * Resets the factory. |
||
69 | */ |
||
70 | 21 | public static function resetPuliFactory() |
|
75 | |||
76 | /** |
||
77 | * Returns the Puli discovery layer. |
||
78 | * |
||
79 | * @return Discovery |
||
80 | */ |
||
81 | 9 | public static function getPuliDiscovery() |
|
92 | |||
93 | /** |
||
94 | * Finds a class. |
||
95 | * |
||
96 | * @param $type |
||
97 | * |
||
98 | * @return string |
||
99 | * |
||
100 | * @throws NotFoundException |
||
101 | */ |
||
102 | 8 | public static function findOneByType($type) |
|
117 | |||
118 | /** |
||
119 | * Finds a class using Puli. |
||
120 | * |
||
121 | * @param $type |
||
122 | * |
||
123 | * @return string |
||
124 | * |
||
125 | * @throws NotFoundException |
||
126 | * @throws PuliNotAvailableException |
||
127 | */ |
||
128 | 8 | private static function puliFindOneByType($type) |
|
147 | |||
148 | /** |
||
149 | * Finds a resource. |
||
150 | * |
||
151 | * @return object |
||
152 | */ |
||
153 | public static function find() |
||
157 | |||
158 | /** |
||
159 | * Evaulates conditions to boolean. |
||
160 | * |
||
161 | * @param mixed $condition |
||
162 | * |
||
163 | * @return bool |
||
164 | */ |
||
165 | 1 | protected static function evaluateCondition($condition) |
|
187 | } |
||
188 |
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: