1 | <?php |
||
13 | abstract class ClassDiscovery |
||
14 | { |
||
15 | /** |
||
16 | * @var GeneratedPuliFactory |
||
17 | */ |
||
18 | 7 | private static $puliFactory; |
|
19 | |||
20 | 7 | /** |
|
21 | * @var Discovery |
||
22 | */ |
||
23 | 7 | private static $puliDiscovery; |
|
24 | 7 | ||
25 | 7 | /** |
|
26 | * @return GeneratedPuliFactory |
||
27 | 7 | */ |
|
28 | 7 | public static function getPuliFactory() |
|
46 | 13 | ||
47 | /** |
||
48 | 13 | * Sets the Puli factory. |
|
49 | * |
||
50 | 6 | * @param object $puliFactory |
|
51 | */ |
||
52 | 1 | public static function setPuliFactory($puliFactory) |
|
61 | |||
62 | 13 | /** |
|
63 | * Resets the factory. |
||
64 | 13 | */ |
|
65 | public static function resetPuliFactory() |
||
70 | 5 | ||
71 | 5 | /** |
|
72 | 4 | * Returns the Puli discovery layer. |
|
73 | * |
||
74 | * @return Discovery |
||
75 | 4 | */ |
|
76 | 4 | public static function getPuliDiscovery() |
|
77 | 4 | { |
|
78 | if (!isset(self::$puliDiscovery)) { |
||
79 | 4 | $factory = self::getPuliFactory(); |
|
80 | $repository = $factory->createRepository(); |
||
81 | |||
82 | 1 | self::$puliDiscovery = $factory->createDiscovery($repository); |
|
83 | } |
||
84 | |||
85 | return self::$puliDiscovery; |
||
86 | } |
||
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: