Complex classes like Credential 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 Credential, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | class Credential extends BackendController |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * Credential model class instance |
||
25 | * @var \gplcart\modules\gapi\models\Credential $credential |
||
26 | */ |
||
27 | protected $credential; |
||
28 | |||
29 | /** |
||
30 | * File transfer module instance |
||
31 | * @var \gplcart\core\models\FileTransfer $file_transfer |
||
32 | */ |
||
33 | protected $file_transfer; |
||
34 | |||
35 | /** |
||
36 | * Pager limit |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $data_limit; |
||
40 | |||
41 | /** |
||
42 | * The current updating credential |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $data_credential = array(); |
||
46 | |||
47 | /** |
||
48 | * Credential type |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $data_type; |
||
52 | |||
53 | /** |
||
54 | * @param ModuleGapiCredentialModel $credential |
||
55 | * @param FileTransferModel $file_transfer |
||
56 | */ |
||
57 | public function __construct(ModuleGapiCredentialModel $credential, FileTransferModel $file_transfer) |
||
64 | |||
65 | /** |
||
66 | * Route page callback |
||
67 | * Displays the add credential page |
||
68 | * @param string $type |
||
69 | */ |
||
70 | public function addCredential($type) |
||
79 | |||
80 | /** |
||
81 | * Handler callback |
||
82 | * Edit "API key" credential page |
||
83 | */ |
||
84 | public function editKeyCredential() |
||
92 | |||
93 | /** |
||
94 | * Handler callback |
||
95 | * Edit "OAuth" credential page |
||
96 | */ |
||
97 | public function editOauthCredential() |
||
105 | |||
106 | /** |
||
107 | * Handler callback |
||
108 | * Edit "Service" credential page |
||
109 | */ |
||
110 | public function editServiceCredential() |
||
118 | |||
119 | /** |
||
120 | * Route page callback |
||
121 | * Displays the edit credential page |
||
122 | * @param int $credential_id |
||
123 | */ |
||
124 | public function editCredential($credential_id) |
||
136 | |||
137 | /** |
||
138 | * Sets the credential data |
||
139 | * @param $credential_id |
||
140 | */ |
||
141 | protected function setCredential($credential_id) |
||
150 | |||
151 | /** |
||
152 | * Set titles on the edit credential page |
||
153 | */ |
||
154 | protected function setTitleEditCredential() |
||
164 | |||
165 | /** |
||
166 | * Set breadcrumbs on the edit credential page |
||
167 | */ |
||
168 | protected function setBreadcrumbEditCredential() |
||
184 | |||
185 | /** |
||
186 | * Validates "API key" credential data |
||
187 | * @return bool |
||
188 | */ |
||
189 | protected function validateKeyCredential() |
||
201 | |||
202 | /** |
||
203 | * Validates "OAuth" credential data |
||
204 | * @return bool |
||
205 | */ |
||
206 | protected function validateOauthCredential() |
||
219 | |||
220 | /** |
||
221 | * Validates "Service" credential data |
||
222 | * @return bool |
||
223 | */ |
||
224 | protected function validateServiceCredential() |
||
236 | |||
237 | /** |
||
238 | * Validates JSON file upload |
||
239 | * @return bool |
||
240 | */ |
||
241 | protected function validateFileUploadCredential() |
||
285 | |||
286 | /** |
||
287 | * Saves the submitted credential data |
||
288 | */ |
||
289 | protected function saveCredential() |
||
297 | |||
298 | /** |
||
299 | * Updates a submitted credential |
||
300 | */ |
||
301 | protected function updateSubmittedCredential() |
||
311 | |||
312 | /** |
||
313 | * Adds a submitted credential |
||
314 | */ |
||
315 | protected function addSubmittedCredential() |
||
328 | |||
329 | /** |
||
330 | * Delete a submitted credential |
||
331 | */ |
||
332 | protected function submitDeleteCredential() |
||
346 | |||
347 | /** |
||
348 | * Route callback |
||
349 | * Displays the credential overview page |
||
350 | */ |
||
351 | public function listCredential() |
||
364 | |||
365 | /** |
||
366 | * Applies an action to the selected credentials |
||
367 | */ |
||
368 | protected function actionListCredential() |
||
387 | |||
388 | /** |
||
389 | * Sets filter parameters |
||
390 | */ |
||
391 | protected function setFilterListCredential() |
||
395 | |||
396 | /** |
||
397 | * Sets pager |
||
398 | * @return array |
||
399 | */ |
||
400 | protected function setPagerListCredential() |
||
412 | |||
413 | /** |
||
414 | * Returns an array of credentials |
||
415 | * @return array |
||
416 | */ |
||
417 | protected function getListCredential() |
||
424 | |||
425 | /** |
||
426 | * Sets title on the credential overview page |
||
427 | */ |
||
428 | protected function setTitleListCredential() |
||
432 | |||
433 | /** |
||
434 | * Sets breadcrumbs on the credential overview page |
||
435 | */ |
||
436 | protected function setBreadcrumbListCredential() |
||
445 | |||
446 | /** |
||
447 | * Render and output the credential overview page |
||
448 | */ |
||
449 | protected function outputListCredential() |
||
453 | |||
454 | } |
||
455 |