Complex classes like RackspaceServer 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 RackspaceServer, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
30 | class RackspaceServer extends AbstractServer implements LoggerAwareInterface |
||
31 | { |
||
32 | use LoggerTrait; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | private $authToken = []; |
||
38 | |||
39 | /** |
||
40 | * Some operations can be performed only inside one region. |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | private $regions = []; |
||
45 | |||
46 | /** |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $options = [ |
||
50 | 'server' => 'https://auth.api.rackspacecloud.com/v1.0', |
||
51 | 'authServer' => 'https://identity.api.rackspacecloud.com/v2.0/tokens', |
||
52 | 'username' => '', |
||
53 | 'apiKey' => '', |
||
54 | 'cache' => true, |
||
55 | 'lifetime' => 86400 |
||
56 | ]; |
||
57 | |||
58 | /** |
||
59 | * Cache store to remember connection. |
||
60 | * |
||
61 | * @invisible |
||
62 | * @var CacheInterface |
||
63 | */ |
||
64 | protected $cache = null; |
||
65 | |||
66 | /** |
||
67 | * @var ClientInterface |
||
68 | */ |
||
69 | protected $client = null; |
||
70 | |||
71 | /** |
||
72 | * @param array $options |
||
73 | * @param CacheInterface|null $cache |
||
74 | * @param FilesInterface|null $files |
||
75 | * @param ClientInterface|null $client |
||
76 | */ |
||
77 | public function __construct( |
||
100 | |||
101 | /** |
||
102 | * @param ClientInterface $client |
||
103 | * |
||
104 | * @return self |
||
105 | */ |
||
106 | public function setClient(ClientInterface $client): RackspaceServer |
||
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | * |
||
116 | * @param ResponseInterface $response Reference. |
||
117 | * |
||
118 | * @return bool |
||
119 | */ |
||
120 | public function exists( |
||
149 | |||
150 | /** |
||
151 | * {@inheritdoc} |
||
152 | */ |
||
153 | public function size(BucketInterface $bucket, string $name) |
||
164 | |||
165 | /** |
||
166 | * {@inheritdoc} |
||
167 | */ |
||
168 | public function put(BucketInterface $bucket, string $name, $source): bool |
||
194 | |||
195 | /** |
||
196 | * {@inheritdoc} |
||
197 | */ |
||
198 | public function allocateStream(BucketInterface $bucket, string $name): StreamInterface |
||
214 | |||
215 | /** |
||
216 | * {@inheritdoc} |
||
217 | * |
||
218 | * @todo debug to figure out why Rackspace is not reliable |
||
219 | * @see https://github.com/rackspace/php-opencloud/issues/477 |
||
220 | */ |
||
221 | public function delete(BucketInterface $bucket, string $name, bool $retry = true) |
||
244 | |||
245 | /** |
||
246 | * {@inheritdoc} |
||
247 | */ |
||
248 | public function rename(BucketInterface $bucket, string $oldName, string $newName): bool |
||
272 | |||
273 | /** |
||
274 | * {@inheritdoc} |
||
275 | */ |
||
276 | public function copy(BucketInterface $bucket, BucketInterface $destination, string $name): bool |
||
306 | |||
307 | /** |
||
308 | * Connect to rackspace servers using new or cached token. |
||
309 | * |
||
310 | * @throws ServerException |
||
311 | */ |
||
312 | protected function connect() |
||
377 | |||
378 | /** |
||
379 | * Reconnect. |
||
380 | * |
||
381 | * @throws ServerException |
||
382 | */ |
||
383 | protected function reconnect() |
||
388 | |||
389 | /** |
||
390 | * Create instance of UriInterface based on provided bucket options and storage object name. |
||
391 | * |
||
392 | * @param BucketInterface $bucket |
||
393 | * @param string $name |
||
394 | * |
||
395 | * @return UriInterface |
||
396 | * @throws ServerException |
||
397 | */ |
||
398 | protected function buildUri(BucketInterface $bucket, string $name): UriInterface |
||
413 | |||
414 | /** |
||
415 | * Create pre-configured object request. |
||
416 | * |
||
417 | * @param string $method |
||
418 | * @param BucketInterface $bucket |
||
419 | * @param string $name |
||
420 | * @param array $headers |
||
421 | * |
||
422 | * @return RequestInterface |
||
423 | */ |
||
424 | protected function buildRequest( |
||
440 | } |