Complex classes like Integrations 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 Integrations, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
36 | abstract class Integrations extends Field |
||
37 | { |
||
38 | use ModifyElementQueryTrait, |
||
39 | NormalizeValueTrait; |
||
40 | |||
41 | /** |
||
42 | * The Plugin's translation category |
||
43 | */ |
||
44 | const TRANSLATION_CATEGORY = ''; |
||
45 | |||
46 | /** |
||
47 | * The action path to preform field actions |
||
48 | */ |
||
49 | const ACTION_PREFORM_ACTION_PATH = ''; |
||
50 | |||
51 | /** |
||
52 | * The action path to preform field actions |
||
53 | */ |
||
54 | const ACTION_PREFORM_ITEM_ACTION_PATH = ''; |
||
55 | |||
56 | /** |
||
57 | * The action path to associate an item |
||
58 | */ |
||
59 | const ACTION_ASSOCIATION_ITEM_PATH = ''; |
||
60 | |||
61 | /** |
||
62 | * The action path to dissociate an item |
||
63 | */ |
||
64 | const ACTION_DISSOCIATION_ITEM_PATH = ''; |
||
65 | |||
66 | /** |
||
67 | * The action path to create an integration object |
||
68 | */ |
||
69 | const ACTION_CREATE_ITEM_PATH = ''; |
||
70 | |||
71 | /** |
||
72 | * The action event name |
||
73 | */ |
||
74 | const EVENT_REGISTER_ACTIONS = 'registerActions'; |
||
75 | |||
76 | /** |
||
77 | * The action event name |
||
78 | */ |
||
79 | const EVENT_REGISTER_AVAILABLE_ACTIONS = 'registerAvailableActions'; |
||
80 | |||
81 | /** |
||
82 | * The item action event name |
||
83 | */ |
||
84 | const EVENT_REGISTER_ITEM_ACTIONS = 'registerItemActions'; |
||
85 | |||
86 | /** |
||
87 | * The item action event name |
||
88 | */ |
||
89 | const EVENT_REGISTER_AVAILABLE_ITEM_ACTIONS = 'registerAvailableItemActions'; |
||
90 | |||
91 | /** |
||
92 | * The input template path |
||
93 | */ |
||
94 | const INPUT_TEMPLATE_PATH = ''; |
||
95 | |||
96 | /** |
||
97 | * The input template path |
||
98 | */ |
||
99 | const INPUT_ITEM_TEMPLATE_PATH = '_inputItem'; |
||
100 | |||
101 | /** |
||
102 | * The input template path |
||
103 | */ |
||
104 | const SETTINGS_TEMPLATE_PATH = ''; |
||
105 | |||
106 | /** |
||
107 | * @var string |
||
108 | */ |
||
109 | public $object; |
||
110 | |||
111 | /** |
||
112 | * @var int|null |
||
113 | */ |
||
114 | public $min; |
||
115 | |||
116 | /** |
||
117 | * @var int|null |
||
118 | */ |
||
119 | public $max; |
||
120 | |||
121 | /** |
||
122 | * @var string |
||
123 | */ |
||
124 | public $viewUrl = ''; |
||
125 | |||
126 | /** |
||
127 | * @var string |
||
128 | */ |
||
129 | public $listUrl = ''; |
||
130 | |||
131 | /** |
||
132 | * @var IntegrationActionInterface[] |
||
133 | */ |
||
134 | public $selectedActions = []; |
||
135 | |||
136 | /** |
||
137 | * @var IntegrationItemActionInterface[] |
||
138 | */ |
||
139 | public $selectedItemActions = []; |
||
140 | |||
141 | /** |
||
142 | * @var string|null |
||
143 | */ |
||
144 | public $selectionLabel; |
||
145 | |||
146 | /** |
||
147 | * @inheritdoc |
||
148 | */ |
||
149 | protected $defaultAvailableActions = []; |
||
150 | |||
151 | /** |
||
152 | * @inheritdoc |
||
153 | */ |
||
154 | protected $defaultAvailableItemActions = []; |
||
155 | |||
156 | /** |
||
157 | * @return string |
||
158 | */ |
||
159 | abstract public static function recordClass(): string; |
||
160 | |||
161 | /** |
||
162 | * @inheritdoc |
||
163 | */ |
||
164 | public static function hasContentColumn(): bool |
||
168 | |||
169 | /** |
||
170 | * @return string |
||
171 | */ |
||
172 | public static function defaultSelectionLabel(): string |
||
176 | |||
177 | /** |
||
178 | * @return string |
||
179 | */ |
||
180 | protected static function tableAlias(): string |
||
186 | |||
187 | /******************************************* |
||
188 | * OBJECT |
||
189 | *******************************************/ |
||
190 | |||
191 | /** |
||
192 | * @return string |
||
193 | */ |
||
194 | public function getObjectLabel(): string |
||
198 | |||
199 | /******************************************* |
||
200 | * VALIDATION |
||
201 | *******************************************/ |
||
202 | |||
203 | /** |
||
204 | * @inheritdoc |
||
205 | */ |
||
206 | public function getElementValidationRules(): array |
||
225 | |||
226 | /******************************************* |
||
227 | * RULES |
||
228 | *******************************************/ |
||
229 | |||
230 | /** |
||
231 | * @inheritdoc |
||
232 | */ |
||
233 | public function rules() |
||
260 | |||
261 | |||
262 | /******************************************* |
||
263 | * SEARCH |
||
264 | *******************************************/ |
||
265 | |||
266 | /** |
||
267 | * @param IntegrationAssociationQuery $value |
||
268 | * @inheritdoc |
||
269 | */ |
||
270 | public function getSearchKeywords($value, ElementInterface $element): string |
||
281 | |||
282 | |||
283 | /******************************************* |
||
284 | * VIEWS |
||
285 | *******************************************/ |
||
286 | |||
287 | /** |
||
288 | * @inheritdoc |
||
289 | * @param IntegrationAssociationQuery $value |
||
290 | * @throws \Twig_Error_Loader |
||
291 | * @throws \yii\base\Exception |
||
292 | */ |
||
293 | public function getInputHtml($value, ElementInterface $element = null): string |
||
304 | |||
305 | /** |
||
306 | * @param IntegrationAssociationQuery $query |
||
307 | * @param ElementInterface|null $element |
||
308 | * @param bool $static |
||
309 | * @return array |
||
310 | * @throws \craft\errors\MissingComponentException |
||
311 | * @throws \yii\base\InvalidConfigException |
||
312 | */ |
||
313 | protected function inputHtmlVariables( |
||
354 | |||
355 | |||
356 | /******************************************* |
||
357 | * ACTIONS |
||
358 | *******************************************/ |
||
359 | |||
360 | /** |
||
361 | * @return IntegrationActionInterface[] |
||
362 | * @throws \craft\errors\MissingComponentException |
||
363 | * @throws \yii\base\InvalidConfigException |
||
364 | */ |
||
365 | public function getAvailableActions(): array |
||
381 | |||
382 | /** |
||
383 | * @param ElementInterface|null $element |
||
384 | * @return IntegrationActionInterface[] |
||
385 | * @throws \craft\errors\MissingComponentException |
||
386 | * @throws \yii\base\InvalidConfigException |
||
387 | */ |
||
388 | public function getActions(ElementInterface $element = null): array |
||
405 | |||
406 | /** |
||
407 | * @return IntegrationActionInterface[] |
||
408 | * @throws \craft\errors\MissingComponentException |
||
409 | * @throws \yii\base\InvalidConfigException |
||
410 | */ |
||
411 | public function getAvailableItemActions(): array |
||
427 | |||
428 | /** |
||
429 | * @param ElementInterface|null $element |
||
430 | * @return IntegrationItemActionInterface[] |
||
431 | * @throws \craft\errors\MissingComponentException |
||
432 | * @throws \yii\base\InvalidConfigException |
||
433 | */ |
||
434 | public function getItemActions(ElementInterface $element = null): array |
||
451 | |||
452 | /** |
||
453 | * @param array $actions |
||
454 | * @param string $instance |
||
455 | * @return array |
||
456 | * @throws \craft\errors\MissingComponentException |
||
457 | * @throws \yii\base\InvalidConfigException |
||
458 | */ |
||
459 | protected function resolveActions(array $actions, string $instance) |
||
474 | |||
475 | /** |
||
476 | * @param ElementInterface|null $element |
||
477 | * @return array |
||
478 | * @throws \craft\errors\MissingComponentException |
||
479 | * @throws \yii\base\InvalidConfigException |
||
480 | */ |
||
481 | protected function getActionHtml(ElementInterface $element = null): array |
||
497 | |||
498 | /** |
||
499 | * @param ElementInterface|null $element |
||
500 | * @return array |
||
501 | * @throws \craft\errors\MissingComponentException |
||
502 | * @throws \yii\base\InvalidConfigException |
||
503 | */ |
||
504 | protected function getItemActionHtml(ElementInterface $element = null): array |
||
520 | |||
521 | |||
522 | |||
523 | /******************************************* |
||
524 | * EVENTS |
||
525 | *******************************************/ |
||
526 | |||
527 | /** |
||
528 | * @param ElementInterface $element |
||
529 | * @param bool $isNew |
||
530 | * @return bool|void |
||
531 | * @throws \Throwable |
||
532 | * @throws \yii\db\StaleObjectException |
||
533 | */ |
||
534 | public function afterElementSave(ElementInterface $element, bool $isNew) |
||
602 | |||
603 | |||
604 | /******************************************* |
||
605 | * SETTINGS |
||
606 | *******************************************/ |
||
607 | |||
608 | /** |
||
609 | * @inheritdoc |
||
610 | * @throws \Twig_Error_Loader |
||
611 | * @throws \yii\base\Exception |
||
612 | */ |
||
613 | public function getSettingsHtml() |
||
620 | |||
621 | /** |
||
622 | * @return array |
||
623 | * @throws \craft\errors\MissingComponentException |
||
624 | * @throws \yii\base\InvalidConfigException |
||
625 | */ |
||
626 | protected function settingsHtmlVariables(): array |
||
635 | |||
636 | /** |
||
637 | * @inheritdoc |
||
638 | */ |
||
639 | public function settingsAttributes(): array |
||
655 | } |
||
656 |