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) |
|
112 | |||
113 | /** |
||
114 | * @param string $path |
||
115 | * @param \DateTimeInterface $expiration |
||
116 | * @param array $options |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | public function getTemporaryUrl($path, DateTimeInterface $expiration, array $options = []) |
||
135 | |||
136 | /** |
||
137 | * @param string $path |
||
138 | * @param string $contents |
||
139 | * @param Config $config |
||
140 | * |
||
141 | * @return array|bool |
||
142 | */ |
||
143 | 2 | public function write($path, $contents, Config $config) |
|
147 | |||
148 | /** |
||
149 | * @param string $path |
||
150 | * @param resource $resource |
||
151 | * @param Config $config |
||
152 | * |
||
153 | * @return array|bool |
||
154 | */ |
||
155 | 2 | public function writeStream($path, $resource, Config $config) |
|
159 | |||
160 | /** |
||
161 | * @param string $path |
||
162 | * @param string $contents |
||
163 | * @param Config $config |
||
164 | * |
||
165 | * @return array|bool |
||
166 | */ |
||
167 | 1 | public function update($path, $contents, Config $config) |
|
171 | |||
172 | /** |
||
173 | * @param string $path |
||
174 | * @param resource $resource |
||
175 | * @param Config $config |
||
176 | * |
||
177 | * @return array|bool |
||
178 | */ |
||
179 | 1 | public function updateStream($path, $resource, Config $config) |
|
183 | |||
184 | /** |
||
185 | * @param string $path |
||
186 | * @param string $newpath |
||
187 | * |
||
188 | * @return bool |
||
189 | */ |
||
190 | 1 | public function rename($path, $newpath) |
|
204 | |||
205 | /** |
||
206 | * @param string $path |
||
207 | * @param string $newpath |
||
208 | * |
||
209 | * @return bool |
||
210 | */ |
||
211 | 1 | public function copy($path, $newpath) |
|
221 | |||
222 | /** |
||
223 | * @param string $path |
||
224 | * |
||
225 | * @return bool |
||
226 | */ |
||
227 | 1 | public function delete($path) |
|
234 | |||
235 | /** |
||
236 | * @param string $dirname |
||
237 | * |
||
238 | * @return bool |
||
239 | */ |
||
240 | 1 | public function deleteDir($dirname) |
|
257 | |||
258 | /** |
||
259 | * @param string $dirname |
||
260 | * @param Config $config |
||
261 | * |
||
262 | * @return array|bool |
||
263 | */ |
||
264 | 1 | public function createDir($dirname, Config $config) |
|
272 | |||
273 | /** |
||
274 | * @param string $path |
||
275 | * @param string $visibility |
||
276 | * |
||
277 | * @return bool |
||
278 | */ |
||
279 | 1 | public function setVisibility($path, $visibility) |
|
290 | |||
291 | /** |
||
292 | * @param string $path |
||
293 | * |
||
294 | * @return bool |
||
295 | */ |
||
296 | 1 | public function has($path) |
|
304 | |||
305 | /** |
||
306 | * @param string $path |
||
307 | * |
||
308 | * @return array|bool |
||
309 | */ |
||
310 | 1 | public function read($path) |
|
323 | |||
324 | /** |
||
325 | * @param string $path |
||
326 | * |
||
327 | * @return array|bool |
||
328 | */ |
||
329 | 1 | public function readStream($path) |
|
337 | |||
338 | /** |
||
339 | * @param string $directory |
||
340 | * @param bool $recursive |
||
341 | * |
||
342 | * @return array|bool |
||
343 | */ |
||
344 | 1 | public function listContents($directory = '', $recursive = false) |
|
356 | |||
357 | /** |
||
358 | * @param string $path |
||
359 | * |
||
360 | * @return array|bool |
||
361 | */ |
||
362 | 5 | public function getMetadata($path) |
|
369 | |||
370 | /** |
||
371 | * @param string $path |
||
372 | * |
||
373 | * @return array|bool |
||
374 | */ |
||
375 | 1 | public function getSize($path) |
|
382 | |||
383 | /** |
||
384 | * @param string $path |
||
385 | * |
||
386 | * @return array|bool |
||
387 | */ |
||
388 | 1 | public function getMimetype($path) |
|
395 | |||
396 | /** |
||
397 | * @param string $path |
||
398 | * |
||
399 | * @return array|bool |
||
400 | */ |
||
401 | 1 | public function getTimestamp($path) |
|
408 | |||
409 | /** |
||
410 | * @param string $path |
||
411 | * |
||
412 | * @return array|bool |
||
413 | */ |
||
414 | 1 | public function getVisibility($path) |
|
432 | |||
433 | /** |
||
434 | * @param array $content |
||
435 | * |
||
436 | * @return array |
||
437 | */ |
||
438 | private function normalizeFileInfo(array $content) |
||
453 | |||
454 | /** |
||
455 | * @param string $directory |
||
456 | * @param bool $recursive |
||
457 | * |
||
458 | * @return mixed |
||
459 | */ |
||
460 | 2 | private function listObjects($directory = '', $recursive = false) |
|
468 | } |
||
469 |