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 |
||
32 | abstract class Integrations extends Field |
||
33 | { |
||
34 | use ModifyElementQueryTrait, |
||
35 | NormalizeValueTrait; |
||
36 | |||
37 | /** |
||
38 | * The Plugin's translation category |
||
39 | */ |
||
40 | const TRANSLATION_CATEGORY = ''; |
||
41 | |||
42 | /** |
||
43 | * The action path to preform field actions |
||
44 | */ |
||
45 | const ACTION_PREFORM_ACTION_PATH = ''; |
||
46 | |||
47 | /** |
||
48 | * The action path to preform field actions |
||
49 | */ |
||
50 | const ACTION_PREFORM_ITEM_ACTION_PATH = ''; |
||
51 | |||
52 | /** |
||
53 | * The action path to associate an item |
||
54 | */ |
||
55 | const ACTION_ASSOCIATION_ITEM_PATH = ''; |
||
56 | |||
57 | /** |
||
58 | * The action path to dissociate an item |
||
59 | */ |
||
60 | const ACTION_DISSOCIATION_ITEM_PATH = ''; |
||
61 | |||
62 | /** |
||
63 | * The action path to create an integration object |
||
64 | */ |
||
65 | const ACTION_CREATE_ITEM_PATH = ''; |
||
66 | |||
67 | /** |
||
68 | * The action event name |
||
69 | */ |
||
70 | const EVENT_REGISTER_ACTIONS = 'registerActions'; |
||
71 | |||
72 | /** |
||
73 | * The action event name |
||
74 | */ |
||
75 | const EVENT_REGISTER_AVAILABLE_ACTIONS = 'registerAvailableActions'; |
||
76 | |||
77 | /** |
||
78 | * The item action event name |
||
79 | */ |
||
80 | const EVENT_REGISTER_ITEM_ACTIONS = 'registerItemActions'; |
||
81 | |||
82 | /** |
||
83 | * The item action event name |
||
84 | */ |
||
85 | const EVENT_REGISTER_AVAILABLE_ITEM_ACTIONS = 'registerAvailableItemActions'; |
||
86 | |||
87 | /** |
||
88 | * The input template path |
||
89 | */ |
||
90 | const INPUT_TEMPLATE_PATH = ''; |
||
91 | |||
92 | /** |
||
93 | * The input template path |
||
94 | */ |
||
95 | const INPUT_ITEM_TEMPLATE_PATH = '_inputItem'; |
||
96 | |||
97 | /** |
||
98 | * The input template path |
||
99 | */ |
||
100 | const SETTINGS_TEMPLATE_PATH = ''; |
||
101 | |||
102 | /** |
||
103 | * @var string |
||
104 | */ |
||
105 | public $object; |
||
106 | |||
107 | /** |
||
108 | * @var int|null |
||
109 | */ |
||
110 | public $min; |
||
111 | |||
112 | /** |
||
113 | * @var int|null |
||
114 | */ |
||
115 | public $max; |
||
116 | |||
117 | /** |
||
118 | * @var string |
||
119 | */ |
||
120 | public $viewUrl = ''; |
||
121 | |||
122 | /** |
||
123 | * @var string |
||
124 | */ |
||
125 | public $listUrl = ''; |
||
126 | |||
127 | /** |
||
128 | * @var IntegrationActionInterface[] |
||
129 | */ |
||
130 | public $selectedActions = []; |
||
131 | |||
132 | /** |
||
133 | * @var IntegrationItemActionInterface[] |
||
134 | */ |
||
135 | public $selectedItemActions = []; |
||
136 | |||
137 | /** |
||
138 | * @var string|null |
||
139 | */ |
||
140 | public $selectionLabel; |
||
141 | |||
142 | /** |
||
143 | * @inheritdoc |
||
144 | */ |
||
145 | protected $defaultAvailableActions = []; |
||
146 | |||
147 | /** |
||
148 | * @inheritdoc |
||
149 | */ |
||
150 | protected $defaultAvailableItemActions = []; |
||
151 | |||
152 | /** |
||
153 | * @return string |
||
154 | */ |
||
155 | abstract public static function recordClass(): string; |
||
156 | |||
157 | /** |
||
158 | * @inheritdoc |
||
159 | */ |
||
160 | public static function hasContentColumn(): bool |
||
164 | |||
165 | /** |
||
166 | * @return string |
||
167 | */ |
||
168 | public static function defaultSelectionLabel(): string |
||
172 | |||
173 | /** |
||
174 | * @return string |
||
175 | */ |
||
176 | protected static function tableAlias(): string |
||
182 | |||
183 | /******************************************* |
||
184 | * OBJECT |
||
185 | *******************************************/ |
||
186 | |||
187 | /** |
||
188 | * @return string |
||
189 | */ |
||
190 | public function getObjectLabel(): string |
||
194 | |||
195 | /******************************************* |
||
196 | * VALIDATION |
||
197 | *******************************************/ |
||
198 | |||
199 | /** |
||
200 | * @inheritdoc |
||
201 | */ |
||
202 | public function getElementValidationRules(): array |
||
221 | |||
222 | /******************************************* |
||
223 | * RULES |
||
224 | *******************************************/ |
||
225 | |||
226 | /** |
||
227 | * @inheritdoc |
||
228 | */ |
||
229 | public function rules() |
||
256 | |||
257 | |||
258 | /******************************************* |
||
259 | * SEARCH |
||
260 | *******************************************/ |
||
261 | |||
262 | /** |
||
263 | * @param IntegrationAssociationQuery $value |
||
264 | * @inheritdoc |
||
265 | */ |
||
266 | public function getSearchKeywords($value, ElementInterface $element): string |
||
277 | |||
278 | |||
279 | /******************************************* |
||
280 | * VIEWS |
||
281 | *******************************************/ |
||
282 | |||
283 | /** |
||
284 | * @inheritdoc |
||
285 | * @param IntegrationAssociationQuery $value |
||
286 | * @throws \Twig_Error_Loader |
||
287 | * @throws \yii\base\Exception |
||
288 | */ |
||
289 | public function getInputHtml($value, ElementInterface $element = null): string |
||
300 | |||
301 | /** |
||
302 | * @param IntegrationAssociationQuery $query |
||
303 | * @param ElementInterface|null $element |
||
304 | * @param bool $static |
||
305 | * @return array |
||
306 | * @throws \craft\errors\MissingComponentException |
||
307 | * @throws \yii\base\InvalidConfigException |
||
308 | */ |
||
309 | protected function inputHtmlVariables( |
||
351 | |||
352 | |||
353 | /******************************************* |
||
354 | * ACTIONS |
||
355 | *******************************************/ |
||
356 | |||
357 | /** |
||
358 | * @return IntegrationActionInterface[] |
||
359 | * @throws \craft\errors\MissingComponentException |
||
360 | * @throws \yii\base\InvalidConfigException |
||
361 | */ |
||
362 | public function getAvailableActions(): array |
||
378 | |||
379 | /** |
||
380 | * @param ElementInterface|null $element |
||
381 | * @return IntegrationActionInterface[] |
||
382 | * @throws \craft\errors\MissingComponentException |
||
383 | * @throws \yii\base\InvalidConfigException |
||
384 | */ |
||
385 | public function getActions(ElementInterface $element = null): array |
||
402 | |||
403 | /** |
||
404 | * @return IntegrationActionInterface[] |
||
405 | * @throws \craft\errors\MissingComponentException |
||
406 | * @throws \yii\base\InvalidConfigException |
||
407 | */ |
||
408 | public function getAvailableItemActions(): array |
||
424 | |||
425 | /** |
||
426 | * @param ElementInterface|null $element |
||
427 | * @return IntegrationItemActionInterface[] |
||
428 | * @throws \craft\errors\MissingComponentException |
||
429 | * @throws \yii\base\InvalidConfigException |
||
430 | */ |
||
431 | public function getItemActions(ElementInterface $element = null): array |
||
448 | |||
449 | /** |
||
450 | * @param array $actions |
||
451 | * @param string $instance |
||
452 | * @return array |
||
453 | * @throws \craft\errors\MissingComponentException |
||
454 | * @throws \yii\base\InvalidConfigException |
||
455 | */ |
||
456 | protected function resolveActions(array $actions, string $instance) |
||
471 | |||
472 | /** |
||
473 | * @param ElementInterface|null $element |
||
474 | * @return array |
||
475 | * @throws \craft\errors\MissingComponentException |
||
476 | * @throws \yii\base\InvalidConfigException |
||
477 | */ |
||
478 | protected function getActionHtml(ElementInterface $element = null): array |
||
494 | |||
495 | /** |
||
496 | * @param ElementInterface|null $element |
||
497 | * @return array |
||
498 | * @throws \craft\errors\MissingComponentException |
||
499 | * @throws \yii\base\InvalidConfigException |
||
500 | */ |
||
501 | protected function getItemActionHtml(ElementInterface $element = null): array |
||
517 | |||
518 | |||
519 | |||
520 | /******************************************* |
||
521 | * EVENTS |
||
522 | *******************************************/ |
||
523 | |||
524 | /** |
||
525 | * @param ElementInterface $element |
||
526 | * @param bool $isNew |
||
527 | * @return bool|void |
||
528 | * @throws \Throwable |
||
529 | * @throws \yii\db\StaleObjectException |
||
530 | */ |
||
531 | public function afterElementSave(ElementInterface $element, bool $isNew) |
||
599 | |||
600 | |||
601 | /******************************************* |
||
602 | * SETTINGS |
||
603 | *******************************************/ |
||
604 | |||
605 | /** |
||
606 | * @inheritdoc |
||
607 | * @throws \Twig_Error_Loader |
||
608 | * @throws \yii\base\Exception |
||
609 | */ |
||
610 | public function getSettingsHtml() |
||
617 | |||
618 | /** |
||
619 | * @return array |
||
620 | * @throws \craft\errors\MissingComponentException |
||
621 | * @throws \yii\base\InvalidConfigException |
||
622 | */ |
||
623 | protected function settingsHtmlVariables(): array |
||
632 | |||
633 | /** |
||
634 | * @inheritdoc |
||
635 | */ |
||
636 | public function settingsAttributes(): array |
||
652 | } |
||
653 |