1 | <?php |
||
13 | abstract class ClassDiscovery |
||
14 | { |
||
15 | /** |
||
16 | * @var GeneratedPuliFactory |
||
17 | */ |
||
18 | 6 | private static $puliFactory; |
|
19 | |||
20 | 6 | /** |
|
21 | * @var Discovery |
||
22 | */ |
||
23 | 6 | private static $puliDiscovery; |
|
24 | 6 | ||
25 | 6 | /** |
|
26 | * @return GeneratedPuliFactory |
||
27 | 6 | */ |
|
28 | 6 | public static function getPuliFactory() |
|
46 | 12 | ||
47 | /** |
||
48 | 12 | * Sets the Puli factory. |
|
49 | * |
||
50 | 5 | * @param object $puliFactory |
|
51 | */ |
||
52 | 1 | public static function setPuliFactory($puliFactory) |
|
61 | |||
62 | 12 | /** |
|
63 | * Resets the factory. |
||
64 | 12 | */ |
|
65 | public static function resetPuliFactory() |
||
70 | 4 | ||
71 | /** |
||
72 | * Returns the Puli discovery layer. |
||
73 | 1 | * |
|
74 | * @return Discovery |
||
75 | */ |
||
76 | public static function getPuliDiscovery() |
||
87 | |||
88 | /** |
||
89 | * Finds a class. |
||
90 | * |
||
91 | * @param $type |
||
92 | * |
||
93 | * @return string |
||
94 | * |
||
95 | * @throws NotFoundException |
||
96 | */ |
||
97 | public static function findOneByType($type) |
||
116 | |||
117 | /** |
||
118 | * Finds a resource. |
||
119 | * |
||
120 | * @return object |
||
121 | */ |
||
122 | public static function find() |
||
126 | |||
127 | /** |
||
128 | * Evaulates conditions to boolean. |
||
129 | * |
||
130 | * @param mixed $condition |
||
131 | * |
||
132 | * @return bool |
||
133 | */ |
||
134 | protected static function evaluateCondition($condition) |
||
156 | } |
||
157 |
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: