1 | <?php |
||
10 | abstract class ReflectorFactory extends BaseFactory |
||
11 | { |
||
12 | const REFLECTION_OBJECT = null; |
||
13 | |||
14 | /** |
||
15 | * @var PHPNativeReflector |
||
16 | */ |
||
17 | protected $reflector; |
||
18 | |||
19 | /** |
||
20 | * @var RawPropertyAccessor |
||
21 | */ |
||
22 | protected $accessor; |
||
23 | |||
24 | /** |
||
25 | * @var SpaarkReflector |
||
26 | */ |
||
27 | protected $object; |
||
28 | |||
29 | 4 | public function __construct(PHPNativeReflector $reflector) |
|
37 | |||
38 | 4 | protected function parseDocComment() |
|
66 | |||
67 | 4 | protected function setBool($name, $value) |
|
68 | { |
||
69 | 4 | switch(strtolower($value)) |
|
70 | { |
||
71 | 4 | case '': |
|
72 | case 'true': |
||
73 | 4 | $value = true; |
|
74 | 4 | break; |
|
75 | |||
76 | case 'false': |
||
77 | $value = false; |
||
78 | break; |
||
79 | |||
80 | default: |
||
81 | $value = (boolean)$value; |
||
82 | } |
||
83 | |||
84 | 4 | $this->accessor->setRawValue($name, $value); |
|
85 | 4 | } |
|
86 | |||
87 | protected function setInt($name, $value) |
||
91 | |||
92 | protected function setMixed($name, $value) |
||
96 | } |
||
97 | |||
98 |
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: