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) |
|
114 | |||
115 | /** |
||
116 | * @param string $path |
||
117 | * @param \DateTimeInterface $expiration |
||
118 | * @param array $options |
||
119 | * |
||
120 | * @return string |
||
121 | */ |
||
122 | public function getTemporaryUrl($path, DateTimeInterface $expiration, array $options = []) |
||
139 | |||
140 | /** |
||
141 | * @param string $path |
||
142 | * @param string $contents |
||
143 | * @param Config $config |
||
144 | * |
||
145 | * @return array|bool |
||
146 | */ |
||
147 | 2 | public function write($path, $contents, Config $config) |
|
151 | |||
152 | /** |
||
153 | * @param string $path |
||
154 | * @param resource $resource |
||
155 | * @param Config $config |
||
156 | * |
||
157 | * @return array|bool |
||
158 | */ |
||
159 | 2 | public function writeStream($path, $resource, Config $config) |
|
163 | |||
164 | /** |
||
165 | * @param string $path |
||
166 | * @param string $contents |
||
167 | * @param Config $config |
||
168 | * |
||
169 | * @return array|bool |
||
170 | */ |
||
171 | 1 | public function update($path, $contents, Config $config) |
|
175 | |||
176 | /** |
||
177 | * @param string $path |
||
178 | * @param resource $resource |
||
179 | * @param Config $config |
||
180 | * |
||
181 | * @return array|bool |
||
182 | */ |
||
183 | 1 | public function updateStream($path, $resource, Config $config) |
|
187 | |||
188 | /** |
||
189 | * @param string $path |
||
190 | * @param string $newpath |
||
191 | * |
||
192 | * @return bool |
||
193 | */ |
||
194 | 1 | public function rename($path, $newpath) |
|
208 | |||
209 | /** |
||
210 | * @param string $path |
||
211 | * @param string $newpath |
||
212 | * |
||
213 | * @return bool |
||
214 | */ |
||
215 | 1 | public function copy($path, $newpath) |
|
225 | |||
226 | /** |
||
227 | * @param string $path |
||
228 | * |
||
229 | * @return bool |
||
230 | */ |
||
231 | 1 | public function delete($path) |
|
238 | |||
239 | /** |
||
240 | * @param string $dirname |
||
241 | * |
||
242 | * @return bool |
||
243 | */ |
||
244 | 1 | public function deleteDir($dirname) |
|
261 | |||
262 | /** |
||
263 | * @param string $dirname |
||
264 | * @param Config $config |
||
265 | * |
||
266 | * @return array|bool |
||
267 | */ |
||
268 | 1 | public function createDir($dirname, Config $config) |
|
276 | |||
277 | /** |
||
278 | * @param string $path |
||
279 | * @param string $visibility |
||
280 | * |
||
281 | * @return bool |
||
282 | */ |
||
283 | 1 | public function setVisibility($path, $visibility) |
|
294 | |||
295 | /** |
||
296 | * @param string $path |
||
297 | * |
||
298 | * @return bool |
||
299 | */ |
||
300 | 1 | public function has($path) |
|
308 | |||
309 | /** |
||
310 | * @param string $path |
||
311 | * |
||
312 | * @return array|bool |
||
313 | */ |
||
314 | 1 | public function read($path) |
|
327 | |||
328 | /** |
||
329 | * @param string $path |
||
330 | * |
||
331 | * @return array|bool |
||
332 | */ |
||
333 | 1 | public function readStream($path) |
|
341 | |||
342 | /** |
||
343 | * @param string $directory |
||
344 | * @param bool $recursive |
||
345 | * |
||
346 | * @return array|bool |
||
347 | */ |
||
348 | 1 | public function listContents($directory = '', $recursive = false) |
|
360 | |||
361 | /** |
||
362 | * @param string $path |
||
363 | * |
||
364 | * @return array|bool |
||
365 | */ |
||
366 | 5 | public function getMetadata($path) |
|
373 | |||
374 | /** |
||
375 | * @param string $path |
||
376 | * |
||
377 | * @return array|bool |
||
378 | */ |
||
379 | 1 | public function getSize($path) |
|
386 | |||
387 | /** |
||
388 | * @param string $path |
||
389 | * |
||
390 | * @return array|bool |
||
391 | */ |
||
392 | 1 | public function getMimetype($path) |
|
399 | |||
400 | /** |
||
401 | * @param string $path |
||
402 | * |
||
403 | * @return array|bool |
||
404 | */ |
||
405 | 1 | public function getTimestamp($path) |
|
412 | |||
413 | /** |
||
414 | * @param string $path |
||
415 | * |
||
416 | * @return array|bool |
||
417 | */ |
||
418 | 1 | public function getVisibility($path) |
|
436 | |||
437 | /** |
||
438 | * @param array $content |
||
439 | * |
||
440 | * @return array |
||
441 | */ |
||
442 | private function normalizeFileInfo(array $content) |
||
457 | |||
458 | /** |
||
459 | * @param string $directory |
||
460 | * @param bool $recursive |
||
461 | * |
||
462 | * @return mixed |
||
463 | */ |
||
464 | 2 | private function listObjects($directory = '', $recursive = false) |
|
472 | } |
||
473 |