1 | <?php |
||
22 | class Pool implements PoolUtilizerInterface |
||
23 | { |
||
24 | /** |
||
25 | * @var LoopInterface |
||
26 | */ |
||
27 | protected $loop; |
||
28 | |||
29 | /** |
||
30 | * @var PoolInfoInterface |
||
31 | */ |
||
32 | protected $pool; |
||
33 | |||
34 | /** |
||
35 | * @var Pool |
||
36 | */ |
||
37 | protected static $instance = null; |
||
38 | |||
39 | /** |
||
40 | * @var boolean |
||
41 | */ |
||
42 | protected static $reset = false; |
||
43 | |||
44 | /** |
||
45 | * @param LoopInterface $loop |
||
46 | * @param array $config |
||
47 | */ |
||
48 | 6 | protected function __construct(LoopInterface $loop, array $config = []) |
|
62 | |||
63 | /** |
||
64 | * @param array $config |
||
65 | * @return array |
||
66 | */ |
||
67 | 6 | protected function applyConfig(array $config) |
|
79 | |||
80 | /** |
||
81 | * @param LoopInterface|null $loop |
||
82 | * @param array $config |
||
83 | * @return Pool |
||
84 | * @throws \Exception |
||
85 | */ |
||
86 | 6 | public static function getInstance(LoopInterface $loop = null, array $config = []) |
|
98 | |||
99 | 23 | public static function reset() |
|
103 | |||
104 | /** |
||
105 | * @param $tableName |
||
106 | * @param $function |
||
107 | * @param array $arguments |
||
108 | * @return PromiseInterface |
||
109 | */ |
||
110 | public function call($tableName, $function, array $arguments) |
||
118 | |||
119 | /** |
||
120 | * @param $tableName |
||
121 | * @param $function |
||
122 | * @param array $arguments |
||
123 | * @return PromiseInterface |
||
124 | */ |
||
125 | protected function poolCall($tableName, $function, array $arguments) |
||
135 | |||
136 | /** |
||
137 | * @param $tableName |
||
138 | * @param $function |
||
139 | * @param array $arguments |
||
140 | * @return PromiseInterface |
||
141 | */ |
||
142 | protected function waitForPoolCall($tableName, $function, array $arguments) |
||
158 | |||
159 | /** |
||
160 | * @inheritDoc |
||
161 | */ |
||
162 | 1 | public function info() |
|
170 | |||
171 | /** |
||
172 | * @return LoopInterface |
||
173 | */ |
||
174 | 1 | public function getLoop() |
|
178 | |||
179 | /** |
||
180 | * @return PoolInfoInterface |
||
181 | */ |
||
182 | 1 | public function getPool() |
|
186 | } |
||
187 |
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: