1 | <?php |
||
21 | class Pool implements PoolUtilizerInterface |
||
22 | { |
||
23 | /** |
||
24 | * @var LoopInterface |
||
25 | */ |
||
26 | protected $loop; |
||
27 | |||
28 | /** |
||
29 | * @var PoolInfoInterface |
||
30 | */ |
||
31 | protected $pool; |
||
32 | |||
33 | /** |
||
34 | * @var Pool |
||
35 | */ |
||
36 | 1 | protected static $instance = null; |
|
37 | |||
38 | 1 | /** |
|
39 | 1 | * @var boolean |
|
40 | 1 | */ |
|
41 | 1 | protected static $reset = false; |
|
42 | 1 | ||
43 | 1 | /** |
|
44 | * @param LoopInterface $loop |
||
45 | 1 | */ |
|
46 | protected function __construct(LoopInterface $loop) |
||
61 | 1 | ||
62 | /** |
||
63 | * @param LoopInterface $loop |
||
64 | 1 | * @return Pool |
|
65 | 1 | * @throws \Exception |
|
66 | */ |
||
67 | 2 | public static function getInstance(LoopInterface $loop = null) |
|
79 | |||
80 | public static function reset() |
||
84 | |||
85 | /** |
||
86 | * @param $tableName |
||
87 | * @param $function |
||
88 | * @param array $arguments |
||
89 | * @return PromiseInterface |
||
90 | */ |
||
91 | public function call($tableName, $function, array $arguments) |
||
99 | |||
100 | /** |
||
101 | * @param $tableName |
||
102 | * @param $function |
||
103 | * @param array $arguments |
||
104 | * @return PromiseInterface |
||
105 | */ |
||
106 | protected function poolCall($tableName, $function, array $arguments) |
||
116 | |||
117 | /** |
||
118 | * @param $tableName |
||
119 | 1 | * @param $function |
|
120 | * @param array $arguments |
||
121 | * @return PromiseInterface |
||
122 | */ |
||
123 | protected function waitForPoolCall($tableName, $function, array $arguments) |
||
139 | |||
140 | /** |
||
141 | * @inheritDoc |
||
142 | */ |
||
143 | public function info() |
||
151 | |||
152 | /** |
||
153 | * @return LoopInterface |
||
154 | */ |
||
155 | public function getLoop() |
||
159 | |||
160 | /** |
||
161 | * @return PoolInfoInterface |
||
162 | */ |
||
163 | public function getPool() |
||
167 | } |
||
168 |
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: