1 | <?php |
||
15 | abstract class AbstractAdapter |
||
16 | { |
||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $driver; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $providerClass; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $config; |
||
31 | |||
32 | /** |
||
33 | * @var AbstractProvider |
||
34 | */ |
||
35 | protected $provider; |
||
36 | |||
37 | /** |
||
38 | * @var mixed |
||
39 | */ |
||
40 | protected $service; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $token; |
||
46 | |||
47 | /** |
||
48 | * @var callable |
||
49 | */ |
||
50 | protected $tokenUpdateCallback; |
||
51 | |||
52 | /** |
||
53 | * DropboxAdapter constructor. |
||
54 | * |
||
55 | * @param array $config |
||
56 | */ |
||
57 | public function __construct(array $config) |
||
61 | |||
62 | /** |
||
63 | * @param $token |
||
64 | * @param null $callback |
||
65 | * |
||
66 | * @return $this |
||
67 | * @paran $callback |
||
68 | * |
||
69 | */ |
||
70 | public function setToken($token, $callback = null) |
||
77 | |||
78 | /** |
||
79 | * @param $token |
||
80 | */ |
||
81 | protected function updateToken($token) |
||
87 | |||
88 | /** |
||
89 | * @param CloudStorage $storage |
||
90 | * @param null $redirectUrl |
||
91 | * |
||
92 | * @return RedirectResponse |
||
93 | */ |
||
94 | public function authorize(CloudStorage $storage, $redirectUrl = null) |
||
112 | |||
113 | /** |
||
114 | * @param CloudStorage $storage |
||
115 | * |
||
116 | * @return void |
||
117 | */ |
||
118 | public function finish(CloudStorage $storage) |
||
135 | |||
136 | /** |
||
137 | * @return string |
||
138 | */ |
||
139 | public function driver() |
||
143 | |||
144 | /** |
||
145 | * @return AbstractProvider |
||
146 | */ |
||
147 | public function provider() |
||
155 | |||
156 | public function setProvider(AbstractProvider $provider) |
||
160 | |||
161 | /** |
||
162 | * @return mixed |
||
163 | */ |
||
164 | public function service() |
||
172 | |||
173 | /** |
||
174 | * @param $service |
||
175 | * |
||
176 | * @return AbstractAdapter |
||
177 | */ |
||
178 | public function setService($service) |
||
184 | |||
185 | /** |
||
186 | * @return AbstractProvider |
||
187 | */ |
||
188 | protected function makeProvider() { |
||
191 | |||
192 | /** |
||
193 | * @return mixed |
||
194 | */ |
||
195 | abstract protected function makeService(); |
||
196 | |||
197 | /** |
||
198 | * @return Quota |
||
199 | */ |
||
200 | abstract function getQuota(); |
||
201 | |||
202 | /** |
||
203 | * @param $user |
||
204 | * |
||
205 | * @return array |
||
206 | */ |
||
207 | abstract protected function mapUserDetails($user); |
||
208 | |||
209 | /** |
||
210 | * @param UploadRequest $request |
||
211 | * |
||
212 | * @return UploadResponse |
||
213 | */ |
||
214 | abstract function upload(UploadRequest $request); |
||
215 | |||
216 | /** |
||
217 | * @param UploadResponse $response |
||
218 | * |
||
219 | * @return UploadResponse |
||
220 | */ |
||
221 | abstract function checkUploadStatus(UploadResponse $response); |
||
222 | |||
223 | /** |
||
224 | * @param string $remotePath |
||
225 | * |
||
226 | * @return bool |
||
227 | */ |
||
228 | abstract function pathExists($remotePath); |
||
229 | } |
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 sub-classes 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 parent class: