1 | <?php |
||
14 | class AsyncTable |
||
15 | { |
||
16 | /** |
||
17 | * @var Pool |
||
18 | */ |
||
19 | protected $pool; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $tableName; |
||
25 | |||
26 | /** |
||
27 | * @var AnnotationReader |
||
28 | */ |
||
29 | protected $annotationReader; |
||
30 | |||
31 | /** |
||
32 | * @var \ReflectionClass |
||
33 | */ |
||
34 | protected $reflectionClass; |
||
35 | |||
36 | /** |
||
37 | * @param Pool $pool |
||
38 | * @param string $tableName |
||
39 | */ |
||
40 | 15 | public function __construct(Pool $pool, $tableName, $tableClass) |
|
47 | |||
48 | /** |
||
49 | * @param $function |
||
50 | * @param array $arguments |
||
51 | * @return PromiseInterface |
||
52 | */ |
||
53 | 14 | public function __call($function, array $arguments = []) |
|
72 | |||
73 | /** |
||
74 | * @param $function |
||
75 | * @param array $arguments |
||
76 | * @return PromiseInterface |
||
77 | */ |
||
78 | 1 | protected function callSync($function, array $arguments = []) |
|
94 | |||
95 | /** |
||
96 | * @param $function |
||
97 | * @param array $arguments |
||
98 | * @return PromiseInterface |
||
99 | */ |
||
100 | protected function callAsync($function, array $arguments = []) |
||
114 | |||
115 | /** |
||
116 | * @param $class |
||
117 | * @return bool |
||
118 | */ |
||
119 | 9 | protected function hasClassAnnotation($class) |
|
123 | |||
124 | /** |
||
125 | * @param $method |
||
126 | * @param $class |
||
127 | * @return bool |
||
128 | */ |
||
129 | 12 | protected function hasMethodAnnotation($method, $class) |
|
134 | |||
135 | /** |
||
136 | * @param $method |
||
137 | * @return bool |
||
138 | */ |
||
139 | 2 | protected function hasNoMethodAnnotation($method) |
|
147 | |||
148 | /** |
||
149 | * @param $function |
||
150 | * @return bool |
||
151 | */ |
||
152 | 14 | protected function returnsQuery($function) |
|
168 | |||
169 | /** |
||
170 | * @param $docBlockContents |
||
171 | * @return DocBlock |
||
172 | */ |
||
173 | 8 | protected function getDocBlock($docBlockContents) |
|
181 | } |
||
182 |
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: