1 | <?php |
||
25 | abstract class ReflectorFactory extends BaseFactory |
||
26 | { |
||
27 | const REFLECTION_OBJECT = null; |
||
28 | |||
29 | /** |
||
30 | * @var PHPNativeReflector |
||
31 | */ |
||
32 | protected $reflector; |
||
33 | |||
34 | /** |
||
35 | * @var RawPropertyAccessor |
||
36 | */ |
||
37 | protected $accessor; |
||
38 | |||
39 | /** |
||
40 | * @var SpaarkReflector |
||
41 | */ |
||
42 | protected $object; |
||
43 | |||
44 | /** |
||
45 | * Creates a new ReflectorFactory using the provided native PHP |
||
46 | * reflector as a basis |
||
47 | * |
||
48 | * @param PHPNativeReflector $reflector The reflector used to |
||
49 | * parse the item |
||
50 | */ |
||
51 | 24 | public function __construct(PHPNativeReflector $reflector) |
|
59 | |||
60 | /** |
||
61 | * Parses the docblock comment for this item and searches for |
||
62 | * annotations |
||
63 | */ |
||
64 | 24 | protected function parseDocComment(array $acceptedParams) |
|
92 | |||
93 | /** |
||
94 | * Sets an annotation which has a boolean value |
||
95 | * |
||
96 | * @param string $name The name of the annotation |
||
97 | * @param string $value The value of the annotation |
||
98 | */ |
||
99 | 22 | protected function setBool($name, $value) |
|
118 | } |
||
119 | |||
120 |
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: