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 | /** |
||
39 | * The Plugin's translation category |
||
40 | */ |
||
41 | const TRANSLATION_CATEGORY = ''; |
||
42 | |||
43 | /** |
||
44 | * The action path to preform field actions |
||
45 | */ |
||
46 | const ACTION_PREFORM_ACTION_PATH = ''; |
||
47 | |||
48 | /** |
||
49 | * The action path to preform field actions |
||
50 | */ |
||
51 | const ACTION_PREFORM_ITEM_ACTION_PATH = ''; |
||
52 | |||
53 | /** |
||
54 | * The action path to associate an item |
||
55 | */ |
||
56 | const ACTION_ASSOCIATION_ITEM_PATH = ''; |
||
57 | |||
58 | /** |
||
59 | * The action path to dissociate an item |
||
60 | */ |
||
61 | const ACTION_DISSOCIATION_ITEM_PATH = ''; |
||
62 | |||
63 | /** |
||
64 | * The action path to create an integration object |
||
65 | */ |
||
66 | const ACTION_CREATE_ITEM_PATH = ''; |
||
67 | |||
68 | /** |
||
69 | * The action event name |
||
70 | */ |
||
71 | const EVENT_REGISTER_ACTIONS = 'registerActions'; |
||
72 | |||
73 | /** |
||
74 | * The action event name |
||
75 | */ |
||
76 | const EVENT_REGISTER_AVAILABLE_ACTIONS = 'registerAvailableActions'; |
||
77 | |||
78 | /** |
||
79 | * The item action event name |
||
80 | */ |
||
81 | const EVENT_REGISTER_ITEM_ACTIONS = 'registerItemActions'; |
||
82 | |||
83 | /** |
||
84 | * The item action event name |
||
85 | */ |
||
86 | const EVENT_REGISTER_AVAILABLE_ITEM_ACTIONS = 'registerAvailableItemActions'; |
||
87 | |||
88 | /** |
||
89 | * The input template path |
||
90 | */ |
||
91 | const INPUT_TEMPLATE_PATH = ''; |
||
92 | |||
93 | /** |
||
94 | * The input template path |
||
95 | */ |
||
96 | const INPUT_ITEM_TEMPLATE_PATH = '_inputItem'; |
||
97 | |||
98 | /** |
||
99 | * The input template path |
||
100 | */ |
||
101 | const SETTINGS_TEMPLATE_PATH = ''; |
||
102 | |||
103 | /** |
||
104 | * @var string |
||
105 | */ |
||
106 | public $object; |
||
107 | |||
108 | /** |
||
109 | * @var int|null |
||
110 | */ |
||
111 | public $min; |
||
112 | |||
113 | /** |
||
114 | * @var int|null |
||
115 | */ |
||
116 | public $max; |
||
117 | |||
118 | /** |
||
119 | * @var string |
||
120 | */ |
||
121 | public $viewUrl = ''; |
||
122 | |||
123 | /** |
||
124 | * @var string |
||
125 | */ |
||
126 | public $listUrl = ''; |
||
127 | |||
128 | /** |
||
129 | * @var IntegrationActionInterface[] |
||
130 | */ |
||
131 | public $selectedActions = []; |
||
132 | |||
133 | /** |
||
134 | * @var IntegrationItemActionInterface[] |
||
135 | */ |
||
136 | public $selectedItemActions = []; |
||
137 | |||
138 | /** |
||
139 | * @var string|null |
||
140 | */ |
||
141 | public $selectionLabel; |
||
142 | |||
143 | /** |
||
144 | * @inheritdoc |
||
145 | */ |
||
146 | protected $defaultAvailableActions = []; |
||
147 | |||
148 | /** |
||
149 | * @inheritdoc |
||
150 | */ |
||
151 | protected $defaultAvailableItemActions = []; |
||
152 | |||
153 | /** |
||
154 | * @return string |
||
155 | */ |
||
156 | abstract public static function recordClass(): string; |
||
157 | |||
158 | /** |
||
159 | * @inheritdoc |
||
160 | */ |
||
161 | public static function hasContentColumn(): bool |
||
165 | |||
166 | /** |
||
167 | * @return string |
||
168 | */ |
||
169 | public static function defaultSelectionLabel(): string |
||
173 | |||
174 | /** |
||
175 | * @return string |
||
176 | */ |
||
177 | protected static function tableAlias(): string |
||
183 | |||
184 | /******************************************* |
||
185 | * OBJECT |
||
186 | *******************************************/ |
||
187 | |||
188 | /** |
||
189 | * @return string |
||
190 | */ |
||
191 | public function getObjectLabel(): string |
||
195 | |||
196 | /******************************************* |
||
197 | * VALIDATION |
||
198 | *******************************************/ |
||
199 | |||
200 | /** |
||
201 | * @inheritdoc |
||
202 | */ |
||
203 | public function getElementValidationRules(): array |
||
222 | |||
223 | /******************************************* |
||
224 | * NORMALIZE VALUE |
||
225 | *******************************************/ |
||
226 | |||
227 | /** |
||
228 | * @param $value |
||
229 | * @param ElementInterface|null $element |
||
230 | * @return IntegrationAssociationQuery |
||
231 | */ |
||
232 | public function normalizeValue( |
||
245 | |||
246 | /** |
||
247 | * @param ElementInterface|null $element |
||
248 | * @return IntegrationAssociationQuery |
||
249 | */ |
||
250 | protected function getQuery(ElementInterface $element = null): IntegrationAssociationQuery |
||
268 | |||
269 | /** |
||
270 | * @param IntegrationAssociationQuery $query |
||
271 | * @param $value |
||
272 | * @param ElementInterface|null $element |
||
273 | */ |
||
274 | protected function normalizeQueryValue( |
||
290 | |||
291 | /** |
||
292 | * @param IntegrationAssociationQuery $query |
||
293 | * @param array $value |
||
294 | * @param ElementInterface|null $element |
||
295 | */ |
||
296 | protected function normalizeQueryInputValues( |
||
309 | |||
310 | /** |
||
311 | * @param $value |
||
312 | * @param int $sortOrder |
||
313 | * @param ElementInterface|null $element |
||
314 | * @return IntegrationAssociation |
||
315 | */ |
||
316 | protected function normalizeQueryInputValue( |
||
340 | |||
341 | /** |
||
342 | * @param IntegrationAssociationQuery $query |
||
343 | */ |
||
344 | protected function normalizeQueryEmptyValue( |
||
350 | |||
351 | /** |
||
352 | * Returns the site ID that target elements should have. |
||
353 | * |
||
354 | * @param ElementInterface|Element|null $element |
||
355 | * |
||
356 | * @return int |
||
357 | */ |
||
358 | protected function targetSiteId(ElementInterface $element = null): int |
||
367 | |||
368 | |||
369 | /******************************************* |
||
370 | * MODIFY ELEMENT QUERY |
||
371 | *******************************************/ |
||
372 | |||
373 | /** |
||
374 | * @inheritdoc |
||
375 | */ |
||
376 | public function modifyElementsQuery(ElementQueryInterface $query, $value) |
||
394 | |||
395 | /** |
||
396 | * @param ElementQuery $query |
||
397 | * @param string $value |
||
398 | */ |
||
399 | protected function modifyElementsQueryForStringValue( |
||
415 | |||
416 | /** |
||
417 | * @param ElementQuery $query |
||
418 | * @param $value |
||
419 | */ |
||
420 | protected function modifyElementsQueryForTargetValue( |
||
442 | |||
443 | /** |
||
444 | * @param ElementQuery $query |
||
445 | * @param string $value |
||
446 | */ |
||
447 | protected function modifyElementsQueryForEmptyValue( |
||
461 | |||
462 | /** |
||
463 | * @param string $alias |
||
464 | * @param string $name |
||
465 | * @param string $operator |
||
466 | * @return string |
||
467 | */ |
||
468 | protected function emptyValueSubSelect( |
||
479 | |||
480 | |||
481 | /******************************************* |
||
482 | * RULES |
||
483 | *******************************************/ |
||
484 | |||
485 | /** |
||
486 | * @inheritdoc |
||
487 | */ |
||
488 | public function rules() |
||
515 | |||
516 | |||
517 | /******************************************* |
||
518 | * SEARCH |
||
519 | *******************************************/ |
||
520 | |||
521 | /** |
||
522 | * @param IntegrationAssociationQuery $value |
||
523 | * @inheritdoc |
||
524 | */ |
||
525 | public function getSearchKeywords($value, ElementInterface $element): string |
||
536 | |||
537 | |||
538 | /******************************************* |
||
539 | * VIEWS |
||
540 | *******************************************/ |
||
541 | |||
542 | /** |
||
543 | * @inheritdoc |
||
544 | * @param IntegrationAssociationQuery $value |
||
545 | * @throws \Twig_Error_Loader |
||
546 | * @throws \yii\base\Exception |
||
547 | */ |
||
548 | public function getInputHtml($value, ElementInterface $element = null): string |
||
559 | |||
560 | /** |
||
561 | * @param IntegrationAssociationQuery $query |
||
562 | * @param ElementInterface|null $element |
||
563 | * @param bool $static |
||
564 | * @return array |
||
565 | * @throws \craft\errors\MissingComponentException |
||
566 | * @throws \yii\base\InvalidConfigException |
||
567 | */ |
||
568 | protected function inputHtmlVariables( |
||
609 | |||
610 | |||
611 | /******************************************* |
||
612 | * ACTIONS |
||
613 | *******************************************/ |
||
614 | |||
615 | /** |
||
616 | * @return IntegrationActionInterface[] |
||
617 | * @throws \craft\errors\MissingComponentException |
||
618 | * @throws \yii\base\InvalidConfigException |
||
619 | */ |
||
620 | public function getAvailableActions(): array |
||
636 | |||
637 | /** |
||
638 | * @param ElementInterface|null $element |
||
639 | * @return IntegrationActionInterface[] |
||
640 | * @throws \craft\errors\MissingComponentException |
||
641 | * @throws \yii\base\InvalidConfigException |
||
642 | */ |
||
643 | public function getActions(ElementInterface $element = null): array |
||
660 | |||
661 | /** |
||
662 | * @return IntegrationActionInterface[] |
||
663 | * @throws \craft\errors\MissingComponentException |
||
664 | * @throws \yii\base\InvalidConfigException |
||
665 | */ |
||
666 | public function getAvailableItemActions(): array |
||
682 | |||
683 | /** |
||
684 | * @param ElementInterface|null $element |
||
685 | * @return IntegrationItemActionInterface[] |
||
686 | * @throws \craft\errors\MissingComponentException |
||
687 | * @throws \yii\base\InvalidConfigException |
||
688 | */ |
||
689 | public function getItemActions(ElementInterface $element = null): array |
||
706 | |||
707 | /** |
||
708 | * @param array $actions |
||
709 | * @param string $instance |
||
710 | * @return array |
||
711 | * @throws \craft\errors\MissingComponentException |
||
712 | * @throws \yii\base\InvalidConfigException |
||
713 | */ |
||
714 | protected function resolveActions(array $actions, string $instance) |
||
729 | |||
730 | /** |
||
731 | * @param ElementInterface|null $element |
||
732 | * @return array |
||
733 | * @throws \craft\errors\MissingComponentException |
||
734 | * @throws \yii\base\InvalidConfigException |
||
735 | */ |
||
736 | protected function getActionHtml(ElementInterface $element = null): array |
||
752 | |||
753 | /** |
||
754 | * @param ElementInterface|null $element |
||
755 | * @return array |
||
756 | * @throws \craft\errors\MissingComponentException |
||
757 | * @throws \yii\base\InvalidConfigException |
||
758 | */ |
||
759 | protected function getItemActionHtml(ElementInterface $element = null): array |
||
775 | |||
776 | |||
777 | |||
778 | /******************************************* |
||
779 | * EVENTS |
||
780 | *******************************************/ |
||
781 | |||
782 | /** |
||
783 | * @param ElementInterface $element |
||
784 | * @param bool $isNew |
||
785 | * @return bool|void |
||
786 | * @throws \Throwable |
||
787 | * @throws \yii\db\StaleObjectException |
||
788 | */ |
||
789 | public function afterElementSave(ElementInterface $element, bool $isNew) |
||
857 | |||
858 | |||
859 | /******************************************* |
||
860 | * SETTINGS |
||
861 | *******************************************/ |
||
862 | |||
863 | /** |
||
864 | * @inheritdoc |
||
865 | * @throws \Twig_Error_Loader |
||
866 | * @throws \yii\base\Exception |
||
867 | */ |
||
868 | public function getSettingsHtml() |
||
875 | |||
876 | /** |
||
877 | * @return array |
||
878 | * @throws \craft\errors\MissingComponentException |
||
879 | * @throws \yii\base\InvalidConfigException |
||
880 | */ |
||
881 | protected function settingsHtmlVariables(): array |
||
890 | |||
891 | /** |
||
892 | * @inheritdoc |
||
893 | */ |
||
894 | public function settingsAttributes(): array |
||
910 | } |
||
911 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.