Complex classes like Adapter often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Adapter, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class Adapter extends AbstractAdapter |
||
17 | { |
||
18 | /** |
||
19 | * @var Client |
||
20 | */ |
||
21 | protected $client; |
||
22 | |||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $config = []; |
||
27 | |||
28 | /** |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $regionMap = [ |
||
32 | 'cn-east' => 'ap-shanghai', |
||
33 | 'cn-sorth' => 'ap-guangzhou', |
||
34 | 'cn-north' => 'ap-beijing-1', |
||
35 | 'cn-south-2' => 'ap-guangzhou-2', |
||
36 | 'cn-southwest' => 'ap-chengdu', |
||
37 | 'sg' => 'ap-singapore', |
||
38 | 'tj' => 'ap-beijing-1', |
||
39 | 'bj' => 'ap-beijing', |
||
40 | 'sh' => 'ap-shanghai', |
||
41 | 'gz' => 'ap-guangzhou', |
||
42 | 'cd' => 'ap-chengdu', |
||
43 | 'sgp' => 'ap-singapore', |
||
44 | ]; |
||
45 | |||
46 | /** |
||
47 | * Adapter constructor. |
||
48 | * |
||
49 | * @param Client $client |
||
50 | * @param array $config |
||
51 | */ |
||
52 | public function __construct(Client $client, array $config) |
||
59 | |||
60 | /** |
||
61 | * @return string |
||
62 | */ |
||
63 | 18 | public function getBucket() |
|
67 | |||
68 | /** |
||
69 | * @return string |
||
70 | */ |
||
71 | 2 | public function getAppId() |
|
75 | |||
76 | /** |
||
77 | * @return string |
||
78 | */ |
||
79 | 2 | public function getRegion() |
|
84 | |||
85 | /** |
||
86 | * @param $path |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | 2 | public function getSourcePath($path) |
|
96 | |||
97 | /** |
||
98 | * @param string $path |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | 6 | public function getUrl($path) |
|
117 | |||
118 | /** |
||
119 | * @param string $path |
||
120 | * @param \DateTimeInterface $expiration |
||
121 | * @param array $options |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | public function getTemporaryUrl($path, DateTimeInterface $expiration, array $options = []) |
||
142 | |||
143 | /** |
||
144 | * @param string $path |
||
145 | * @param string $contents |
||
146 | * @param Config $config |
||
147 | * |
||
148 | * @return array|bool |
||
149 | */ |
||
150 | 2 | public function write($path, $contents, Config $config) |
|
154 | |||
155 | /** |
||
156 | * @param string $path |
||
157 | * @param resource $resource |
||
158 | * @param Config $config |
||
159 | * |
||
160 | * @return array|bool |
||
161 | */ |
||
162 | 2 | public function writeStream($path, $resource, Config $config) |
|
166 | |||
167 | /** |
||
168 | * @param string $path |
||
169 | * @param string $contents |
||
170 | * @param Config $config |
||
171 | * |
||
172 | * @return array|bool |
||
173 | */ |
||
174 | 1 | public function update($path, $contents, Config $config) |
|
178 | |||
179 | /** |
||
180 | * @param string $path |
||
181 | * @param resource $resource |
||
182 | * @param Config $config |
||
183 | * |
||
184 | * @return array|bool |
||
185 | */ |
||
186 | 1 | public function updateStream($path, $resource, Config $config) |
|
190 | |||
191 | /** |
||
192 | * @param string $path |
||
193 | * @param string $newpath |
||
194 | * |
||
195 | * @return bool |
||
196 | */ |
||
197 | 1 | public function rename($path, $newpath) |
|
205 | |||
206 | /** |
||
207 | * @param string $path |
||
208 | * @param string $newpath |
||
209 | * |
||
210 | * @return bool |
||
211 | */ |
||
212 | 2 | public function copy($path, $newpath) |
|
218 | |||
219 | /** |
||
220 | * @param string $path |
||
221 | * |
||
222 | * @return bool |
||
223 | */ |
||
224 | 1 | public function delete($path) |
|
231 | |||
232 | /** |
||
233 | * @param string $dirname |
||
234 | * |
||
235 | * @return bool |
||
236 | */ |
||
237 | 1 | public function deleteDir($dirname) |
|
254 | |||
255 | /** |
||
256 | * @param string $dirname |
||
257 | * @param Config $config |
||
258 | * |
||
259 | * @return array|bool |
||
260 | */ |
||
261 | 1 | public function createDir($dirname, Config $config) |
|
269 | |||
270 | /** |
||
271 | * @param string $path |
||
272 | * @param string $visibility |
||
273 | * |
||
274 | * @return bool |
||
275 | */ |
||
276 | 1 | public function setVisibility($path, $visibility) |
|
287 | |||
288 | /** |
||
289 | * @param string $path |
||
290 | * |
||
291 | * @return bool |
||
292 | */ |
||
293 | 1 | public function has($path) |
|
301 | |||
302 | /** |
||
303 | * @param string $path |
||
304 | * |
||
305 | * @return array|bool |
||
306 | */ |
||
307 | 1 | public function read($path) |
|
320 | |||
321 | /** |
||
322 | * @param string $path |
||
323 | * |
||
324 | * @return array|bool |
||
325 | */ |
||
326 | 1 | public function readStream($path) |
|
334 | |||
335 | /** |
||
336 | * @param string $directory |
||
337 | * @param bool $recursive |
||
338 | * |
||
339 | * @return array|bool |
||
340 | */ |
||
341 | 1 | public function listContents($directory = '', $recursive = false) |
|
353 | |||
354 | /** |
||
355 | * @param string $path |
||
356 | * |
||
357 | * @return array|bool |
||
358 | */ |
||
359 | 5 | public function getMetadata($path) |
|
366 | |||
367 | /** |
||
368 | * @param string $path |
||
369 | * |
||
370 | * @return array|bool |
||
371 | */ |
||
372 | 1 | public function getSize($path) |
|
379 | |||
380 | /** |
||
381 | * @param string $path |
||
382 | * |
||
383 | * @return array|bool |
||
384 | */ |
||
385 | 1 | public function getMimetype($path) |
|
392 | |||
393 | /** |
||
394 | * @param string $path |
||
395 | * |
||
396 | * @return array|bool |
||
397 | */ |
||
398 | 1 | public function getTimestamp($path) |
|
405 | |||
406 | /** |
||
407 | * @param string $path |
||
408 | * |
||
409 | * @return array|bool |
||
410 | */ |
||
411 | 1 | public function getVisibility($path) |
|
429 | |||
430 | /** |
||
431 | * @param array $content |
||
432 | * |
||
433 | * @return array |
||
434 | */ |
||
435 | private function normalizeFileInfo(array $content) |
||
450 | |||
451 | /** |
||
452 | * @param string $directory |
||
453 | * @param bool $recursive |
||
454 | * |
||
455 | * @return mixed |
||
456 | */ |
||
457 | 2 | private function listObjects($directory = '', $recursive = false) |
|
465 | } |
||
466 |