Complex classes like Cloud 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.
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 Cloud, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
29 | class Cloud implements CloudInterface |
||
30 | { |
||
31 | /** |
||
32 | * The client which is used to perform the requests to the REST api |
||
33 | * |
||
34 | * @var HttpClientInterface |
||
35 | */ |
||
36 | private $httpClient; |
||
37 | |||
38 | /** |
||
39 | * @var TransformerRegistryInterface |
||
40 | */ |
||
41 | private $transformers; |
||
42 | |||
43 | /** |
||
44 | * {@inheritDoc} |
||
45 | */ |
||
46 | 58 | public function setHttpClient(HttpClientInterface $httpClient) |
|
50 | |||
51 | /** |
||
52 | * {@inheritDoc} |
||
53 | */ |
||
54 | 3 | public function getHttpClient() |
|
58 | |||
59 | /** |
||
60 | * {@inheritDoc} |
||
61 | */ |
||
62 | 58 | public function setTransformers(TransformerRegistryInterface $transformers) |
|
66 | |||
67 | /** |
||
68 | * {@inheritDoc} |
||
69 | */ |
||
70 | 1 | public function getTransformers() |
|
74 | |||
75 | /** |
||
76 | * {@inheritDoc} |
||
77 | */ |
||
78 | 1 | public function getVideos() |
|
85 | |||
86 | /** |
||
87 | * {@inheritDoc} |
||
88 | */ |
||
89 | 3 | public function getVideosForPagination($page = 1, $per_page = 100) |
|
105 | |||
106 | /** |
||
107 | * {@inheritDoc} |
||
108 | */ |
||
109 | 1 | public function getVideo($videoId) |
|
116 | |||
117 | /** |
||
118 | * {@inheritDoc} |
||
119 | */ |
||
120 | 1 | public function getVideoMetadata($videoId) |
|
126 | |||
127 | /** |
||
128 | * {@inheritDoc} |
||
129 | */ |
||
130 | 1 | public function deleteVideo(Video $video) |
|
134 | |||
135 | /** |
||
136 | * Deletes the source of a video from the storage. |
||
137 | * |
||
138 | * @param Video $video The video whose source will be deleted |
||
139 | * |
||
140 | * @return string The server response |
||
141 | */ |
||
142 | 1 | public function deleteVideoSource(Video $video) |
|
146 | |||
147 | /** |
||
148 | * {@inheritDoc} |
||
149 | */ |
||
150 | 5 | public function encodeVideoByUrl($url, array $profiles = array(), $pathFormat = null, $payload = null) |
|
154 | |||
155 | /** |
||
156 | * {@inheritDoc} |
||
157 | */ |
||
158 | 5 | public function encodeVideoFile($localPath, array $profiles = array(), $pathFormat = null, $payload = null) |
|
162 | |||
163 | /** |
||
164 | * {@inheritDoc} |
||
165 | */ |
||
166 | 3 | public function registerUpload($filename, $fileSize, array $profiles = null, $useAllProfiles = false) |
|
184 | |||
185 | /** |
||
186 | * {@inheritDoc} |
||
187 | */ |
||
188 | 12 | public function getEncodings(array $filter = null) |
|
195 | |||
196 | /** |
||
197 | * {@inheritDoc} |
||
198 | */ |
||
199 | 2 | public function getEncodingsWithStatus($status, array $filter = null) |
|
209 | |||
210 | /** |
||
211 | * {@inheritDoc} |
||
212 | */ |
||
213 | 2 | public function getEncodingsForProfile(Profile $profile, array $filter = null) |
|
223 | |||
224 | /** |
||
225 | * {@inheritDoc} |
||
226 | */ |
||
227 | 2 | public function getEncodingsForProfileById($profileId, array $filter = null) |
|
237 | |||
238 | /** |
||
239 | * {@inheritDoc} |
||
240 | */ |
||
241 | 2 | public function getEncodingsForProfileByName($profileName, array $filter = null) |
|
251 | |||
252 | /** |
||
253 | * {@inheritDoc} |
||
254 | */ |
||
255 | 2 | public function getEncodingsForVideo(Video $video, array $filter = null) |
|
265 | |||
266 | /** |
||
267 | * {@inheritDoc} |
||
268 | */ |
||
269 | 1 | public function getEncoding($encodingId) |
|
276 | |||
277 | /** |
||
278 | * {@inheritDoc} |
||
279 | */ |
||
280 | 1 | public function createEncoding(Video $video, Profile $profile) |
|
284 | |||
285 | /** |
||
286 | * {@inheritDoc} |
||
287 | */ |
||
288 | 2 | public function createEncodingWithProfileId(Video $video, $profileId) |
|
295 | |||
296 | /** |
||
297 | * {@inheritDoc} |
||
298 | */ |
||
299 | 1 | public function createEncodingWithProfileName(Video $video, $profileName) |
|
306 | |||
307 | /** |
||
308 | * {@inheritDoc} |
||
309 | */ |
||
310 | 1 | public function cancelEncoding(Encoding $encoding) |
|
314 | |||
315 | /** |
||
316 | * {@inheritDoc} |
||
317 | */ |
||
318 | 1 | public function retryEncoding(Encoding $encoding) |
|
322 | |||
323 | /** |
||
324 | * {@inheritDoc} |
||
325 | */ |
||
326 | 1 | public function deleteEncoding(Encoding $encoding) |
|
330 | |||
331 | /** |
||
332 | * {@inheritDoc} |
||
333 | */ |
||
334 | 1 | public function getProfiles() |
|
341 | |||
342 | /** |
||
343 | * {@inheritDoc} |
||
344 | */ |
||
345 | 1 | public function getProfile($profileId) |
|
352 | |||
353 | /** |
||
354 | * {@inheritDoc} |
||
355 | */ |
||
356 | 1 | public function addProfile(Profile $profile) |
|
364 | |||
365 | /** |
||
366 | * {@inheritDoc} |
||
367 | */ |
||
368 | 1 | public function addProfileFromPreset($presetName) |
|
378 | |||
379 | /** |
||
380 | * {@inheritDoc} |
||
381 | */ |
||
382 | 1 | public function setProfile(Profile $profile) |
|
392 | |||
393 | /** |
||
394 | * {@inheritDoc} |
||
395 | */ |
||
396 | 1 | public function deleteProfile(Profile $profile) |
|
400 | |||
401 | /** |
||
402 | * {@inheritDoc} |
||
403 | */ |
||
404 | 2 | public function getCloud($cloudId = null) |
|
415 | |||
416 | /** |
||
417 | * {@inheritDoc} |
||
418 | */ |
||
419 | 2 | public function setCloud(array $data, $cloudId = null) |
|
430 | |||
431 | /** |
||
432 | * {@inheritDoc} |
||
433 | */ |
||
434 | 1 | public function getNotifications() |
|
441 | |||
442 | /** |
||
443 | * {@inheritDoc} |
||
444 | */ |
||
445 | 1 | public function setNotifications(Notifications $notifications) |
|
453 | |||
454 | 10 | private function doEncodeVideo(array $parameters, array $profiles, $pathFormat, $payload) |
|
473 | |||
474 | 3 | private function doCreateEncoding(array $params) |
|
481 | } |
||
482 |