Conditions | 8 |
Paths | 1 |
Total Lines | 57 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 | Event::on( |
||
102 | Plugins::class, |
||
103 | Plugins::EVENT_AFTER_LOAD_PLUGINS, |
||
104 | function () { |
||
105 | $this->maybeRegisterResources(); |
||
106 | } |
||
107 | ); |
||
108 | |||
109 | Craft::info( |
||
110 | Craft::t( |
||
111 | 'cache-flag', |
||
112 | '{name} plugin loaded', |
||
113 | ['name' => $this->name] |
||
114 | ), |
||
115 | __METHOD__ |
||
116 | ); |
||
117 | } |
||
118 | |||
119 | // Protected Methods |
||
120 | // ========================================================================= |
||
121 | |||
122 | /** |
||
123 | * Add event listeners for cache breaking |
||
124 | */ |
||
125 | protected function addElementEventListeners() |
||
126 | { |
||
127 | Event::on( |
||
128 | Elements::class, |
||
129 | Elements::EVENT_AFTER_SAVE_ELEMENT, |
||
130 | function (ElementEvent $event) { |
||
131 | $element = $event->element; |
||
132 | if (!$element || ElementHelper::isDraftOrRevision($element)) { |
||
133 | return; |
||
134 | } |
||
135 | CacheFlag::$plugin->cacheFlag->invalidateFlaggedCachesByElement($element); |
||
136 | } |
||
137 | ); |
||
138 | |||
139 | Event::on( |
||
140 | Elements::class, |
||
141 | Elements::EVENT_BEFORE_DELETE_ELEMENT, |
||
142 | function (ElementEvent $event) { |
||
143 | $element = $event->element; |
||
144 | if (!$element || ElementHelper::isDraftOrRevision($element)) { |
||
145 | return; |
||
146 | } |
||
147 | CacheFlag::$plugin->cacheFlag->invalidateFlaggedCachesByElement($element); |
||
148 | } |
||
149 | ); |
||
150 | |||
151 | Event::on( |
||
152 | Structures::class, |
||
153 | Structures::EVENT_AFTER_MOVE_ELEMENT, |
||
154 | function (MoveElementEvent $event) { |
||
155 | $element = $event->element; |
||
156 | if (!$element || ElementHelper::isDraftOrRevision($element)) { |
||
157 | return; |
||
158 | } |
||
222 |