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 | */ |
||
47 | 6 | protected function __construct(LoopInterface $loop) |
|
63 | |||
64 | /** |
||
65 | * @param LoopInterface $loop |
||
66 | * @return Pool |
||
67 | * @throws \Exception |
||
68 | */ |
||
69 | 6 | public static function getInstance(LoopInterface $loop = null) |
|
81 | |||
82 | 23 | public static function reset() |
|
86 | |||
87 | /** |
||
88 | * @param $tableName |
||
89 | * @param $function |
||
90 | * @param array $arguments |
||
91 | * @return PromiseInterface |
||
92 | */ |
||
93 | public function call($tableName, $function, array $arguments) |
||
101 | |||
102 | /** |
||
103 | * @param $tableName |
||
104 | * @param $function |
||
105 | * @param array $arguments |
||
106 | * @return PromiseInterface |
||
107 | */ |
||
108 | protected function poolCall($tableName, $function, array $arguments) |
||
118 | |||
119 | /** |
||
120 | * @param $tableName |
||
121 | * @param $function |
||
122 | * @param array $arguments |
||
123 | * @return PromiseInterface |
||
124 | */ |
||
125 | protected function waitForPoolCall($tableName, $function, array $arguments) |
||
141 | |||
142 | /** |
||
143 | * @inheritDoc |
||
144 | */ |
||
145 | 1 | public function info() |
|
153 | |||
154 | /** |
||
155 | * @return LoopInterface |
||
156 | */ |
||
157 | 1 | public function getLoop() |
|
161 | |||
162 | /** |
||
163 | * @return PoolInfoInterface |
||
164 | */ |
||
165 | 1 | public function getPool() |
|
169 | } |
||
170 |
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: