Complex classes like AbstractReportingCloud 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 AbstractReportingCloud, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
29 | abstract class AbstractReportingCloud |
||
30 | { |
||
31 | /** |
||
32 | * Default date/time format of backend is 'ISO 8601' |
||
33 | * |
||
34 | * Note, last letter is 'P' and not 'O': |
||
35 | * |
||
36 | * O - Difference to Greenwich time (GMT) in hours (e.g. +0200) |
||
37 | * P - Difference to Greenwich time (GMT) with colon between hours and minutes (e.g. +02:00) |
||
38 | * |
||
39 | * Backend uses the 'P' variant |
||
40 | * |
||
41 | * @const DEFAULT_DATE_FORMAT |
||
42 | */ |
||
43 | const DEFAULT_DATE_FORMAT = 'Y-m-d\TH:i:sP'; |
||
44 | |||
45 | /** |
||
46 | * Default time zone of backend |
||
47 | * |
||
48 | * @const DEFAULT_TIME_ZONE |
||
49 | */ |
||
50 | const DEFAULT_TIME_ZONE = 'UTC'; |
||
51 | |||
52 | /** |
||
53 | * Default base URI of backend |
||
54 | * |
||
55 | * @const DEFAULT_BASE_URI |
||
56 | */ |
||
57 | const DEFAULT_BASE_URI = 'https://api.reporting.cloud'; |
||
58 | |||
59 | /** |
||
60 | * Default version string of backend |
||
61 | * |
||
62 | * @const DEFAULT_VERSION |
||
63 | */ |
||
64 | const DEFAULT_VERSION = 'v1'; |
||
65 | |||
66 | /** |
||
67 | * Default timeout of backend in seconds |
||
68 | * |
||
69 | * @const DEFAULT_TIMEOUT |
||
70 | */ |
||
71 | const DEFAULT_TIMEOUT = 120; // seconds |
||
72 | |||
73 | /** |
||
74 | * Default test flag of backend |
||
75 | * |
||
76 | * @const DEFAULT_TEST |
||
77 | */ |
||
78 | const DEFAULT_TEST = false; |
||
79 | |||
80 | /** |
||
81 | * Default debug flag of REST client |
||
82 | * |
||
83 | * @const DEFAULT_DEBUG |
||
84 | */ |
||
85 | const DEFAULT_DEBUG = false; |
||
86 | |||
87 | /** |
||
88 | * Backend username |
||
89 | * |
||
90 | * @var string |
||
91 | */ |
||
92 | protected $username; |
||
93 | |||
94 | /** |
||
95 | * Backend password |
||
96 | * |
||
97 | * @var string |
||
98 | */ |
||
99 | protected $password; |
||
100 | |||
101 | /** |
||
102 | * When true, backend prints "TEST MODE" water mark into output document, but API call does not count against quota |
||
103 | * |
||
104 | * @var boolean |
||
105 | */ |
||
106 | protected $test; |
||
107 | |||
108 | /** |
||
109 | * Backend base URI |
||
110 | * |
||
111 | * @var string |
||
112 | */ |
||
113 | protected $baseUri; |
||
114 | |||
115 | /** |
||
116 | * Backend version string |
||
117 | * |
||
118 | * @var string |
||
119 | */ |
||
120 | protected $version; |
||
121 | |||
122 | /** |
||
123 | * Backend timeout in seconds |
||
124 | * |
||
125 | * @var integer |
||
126 | */ |
||
127 | protected $timeout; |
||
128 | |||
129 | /** |
||
130 | * REST client to backend |
||
131 | * |
||
132 | * @var Client |
||
133 | */ |
||
134 | protected $client; |
||
135 | |||
136 | /** |
||
137 | * Debug flag of REST client |
||
138 | * |
||
139 | * @var boolean |
||
140 | */ |
||
141 | protected $debug; |
||
142 | |||
143 | /** |
||
144 | * AbstractReportingCloud constructor |
||
145 | * |
||
146 | * @param array $options |
||
147 | */ |
||
148 | 59 | public function __construct($options = []) |
|
178 | |||
179 | /** |
||
180 | * Return the REST client of the backend web service |
||
181 | * |
||
182 | * @return \GuzzleHttp\Client |
||
183 | */ |
||
184 | 18 | public function getClient() |
|
206 | |||
207 | /** |
||
208 | * Set the REST client of the backend web service |
||
209 | * |
||
210 | * @param Client $client REST client |
||
211 | * |
||
212 | * @return ReportingCloud |
||
213 | */ |
||
214 | 18 | public function setClient(Client $client) |
|
220 | |||
221 | /** |
||
222 | * Return the base URI of the backend web service |
||
223 | * |
||
224 | * @return string |
||
225 | */ |
||
226 | 22 | public function getBaseUri() |
|
234 | |||
235 | /** |
||
236 | * Set the base URI of the backend web service |
||
237 | * |
||
238 | * @param string $baseUri Base URI |
||
239 | * |
||
240 | * @return ReportingCloud |
||
241 | */ |
||
242 | 22 | public function setBaseUri($baseUri) |
|
248 | |||
249 | /** |
||
250 | * Get the timeout (in seconds) of the backend web service |
||
251 | * |
||
252 | * @return integer |
||
253 | */ |
||
254 | 21 | public function getTimeout() |
|
262 | |||
263 | /** |
||
264 | * Set the timeout (in seconds) of the backend web service |
||
265 | * |
||
266 | * @param integer $timeout Timeout |
||
267 | * |
||
268 | * @return ReportingCloud |
||
269 | */ |
||
270 | 21 | public function setTimeout($timeout) |
|
276 | |||
277 | /** |
||
278 | * Return the username |
||
279 | * |
||
280 | * @return string |
||
281 | */ |
||
282 | 21 | public function getUsername() |
|
286 | |||
287 | /** |
||
288 | * Set the username |
||
289 | * |
||
290 | * @param string $username Username |
||
291 | * |
||
292 | * @return ReportingCloud |
||
293 | */ |
||
294 | 56 | public function setUsername($username) |
|
300 | |||
301 | /** |
||
302 | * Return the password |
||
303 | * |
||
304 | * @return string |
||
305 | */ |
||
306 | 21 | public function getPassword() |
|
310 | |||
311 | /** |
||
312 | * Set the password |
||
313 | * |
||
314 | * @param string $password Password |
||
315 | * |
||
316 | * @return ReportingCloud |
||
317 | */ |
||
318 | 56 | public function setPassword($password) |
|
324 | |||
325 | /** |
||
326 | * Return the test flag |
||
327 | * |
||
328 | * @return mixed |
||
329 | */ |
||
330 | 14 | public function getTest() |
|
338 | |||
339 | /** |
||
340 | * Set the test flag |
||
341 | * |
||
342 | * @param boolean $test Test flag |
||
343 | * |
||
344 | * @return ReportingCloud |
||
345 | */ |
||
346 | 14 | public function setTest($test) |
|
352 | |||
353 | /** |
||
354 | * Return the debug flag |
||
355 | * |
||
356 | * @return mixed |
||
357 | */ |
||
358 | 21 | public function getDebug() |
|
366 | |||
367 | /** |
||
368 | * Set the debug flag |
||
369 | * |
||
370 | * @param boolean $debug Debug flag |
||
371 | * |
||
372 | * @return ReportingCloud |
||
373 | */ |
||
374 | 21 | public function setDebug($debug) |
|
380 | |||
381 | /** |
||
382 | * Construct URI with version number |
||
383 | * |
||
384 | * @param string $uri URI |
||
385 | * |
||
386 | * @return string |
||
387 | */ |
||
388 | 17 | protected function uri($uri) |
|
392 | |||
393 | /** |
||
394 | * Get the version string of the backend web service |
||
395 | * |
||
396 | * @return string |
||
397 | */ |
||
398 | 20 | public function getVersion() |
|
406 | |||
407 | /** |
||
408 | * Set the version string of the backend web service |
||
409 | * |
||
410 | * @param string $version Version string |
||
411 | * |
||
412 | * @return ReportingCloud |
||
413 | */ |
||
414 | 2 | public function setVersion($version) |
|
420 | |||
421 | /** |
||
422 | * Request the URI with options |
||
423 | * |
||
424 | * @param string $method HTTP method |
||
425 | * @param string $uri URI |
||
426 | * @param array $options Options |
||
427 | * |
||
428 | * @return mixed|null|\Psr\Http\Message\ResponseInterface |
||
429 | * |
||
430 | * @throws RuntimeException |
||
431 | */ |
||
432 | 17 | protected function request($method, $uri, $options) |
|
459 | |||
460 | /** |
||
461 | * Using the passed propertyMap, recursively normalizes the keys of the passed array |
||
462 | * |
||
463 | * @param array $array Array |
||
464 | * @param PropertyMap $propertyMap PropertyMap |
||
465 | * |
||
466 | * @return array |
||
467 | */ |
||
468 | 5 | protected function normalizeArrayKeys($array, PropertyMap $propertyMap) |
|
485 | |||
486 | /** |
||
487 | * Assemble MergeSettings array to pass to ReportingCloud |
||
488 | * |
||
489 | * @param array $mergeSettings MergeSettings array |
||
490 | * |
||
491 | * @return array |
||
492 | */ |
||
493 | 8 | protected function assembleMergeSettings($mergeSettings) |
|
516 | |||
517 | } |