Conditions | 8 |
Paths | 1 |
Total Lines | 57 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
101 | protected function addEventListeners() |
||
102 | { |
||
103 | Event::on( |
||
104 | Elements::class, |
||
105 | Elements::EVENT_AFTER_SAVE_ELEMENT, |
||
106 | function (ElementEvent $event) { |
||
107 | if ($event->element) { |
||
108 | CacheFlag::$plugin->cacheFlag->deleteFlaggedCachesByElement($event->element); |
||
109 | } |
||
110 | } |
||
111 | ); |
||
112 | |||
113 | Event::on( |
||
114 | Elements::class, |
||
115 | Elements::EVENT_BEFORE_DELETE_ELEMENT, |
||
116 | function (ElementEvent $event) { |
||
117 | if ($event->element) { |
||
118 | CacheFlag::$plugin->cacheFlag->deleteFlaggedCachesByElement($event->element); |
||
119 | } |
||
120 | } |
||
121 | ); |
||
122 | |||
123 | Event::on( |
||
124 | Structures::class, |
||
125 | Structures::EVENT_AFTER_MOVE_ELEMENT, |
||
126 | function (MoveElementEvent $event) { |
||
127 | if ($event->element) { |
||
128 | CacheFlag::$plugin->cacheFlag->deleteFlaggedCachesByElement($event->element); |
||
129 | } |
||
130 | } |
||
131 | ); |
||
132 | |||
133 | Event::on( |
||
134 | Elements::class, |
||
135 | Elements::EVENT_AFTER_PERFORM_ACTION, |
||
136 | function (ElementActionEvent $event) { |
||
137 | |||
138 | /* @var ElementQueryInterface|null $criteria */ |
||
139 | $criteria = $event->criteria; |
||
140 | |||
141 | if (!$criteria) { |
||
142 | return; |
||
143 | } |
||
144 | |||
145 | /* @var ElementActionInterface|null $action */ |
||
146 | $action = $event->action; |
||
147 | |||
148 | if (!$action || !\in_array(\get_class($action), [ |
||
149 | SetStatus::class, |
||
150 | ])) { |
||
151 | return; |
||
152 | } |
||
153 | |||
154 | $elements = $criteria->all(); |
||
155 | |||
156 | foreach ($elements as $element) { |
||
157 | CacheFlag::$plugin->cacheFlag->deleteFlaggedCachesByElement($element); |
||
158 | } |
||
196 |