| Conditions | 4 |
| Paths | 4 |
| Total Lines | 65 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 153 | protected function installEventListeners(): void |
||
| 154 | { |
||
| 155 | // Remember the name of the currently rendering template |
||
| 156 | // Handler: View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE |
||
| 157 | Event::on( |
||
| 158 | View::class, |
||
| 159 | View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE, |
||
| 160 | static function(TemplateEvent $event) { |
||
| 161 | self::$templateName = $event->template; |
||
| 162 | } |
||
| 163 | ); |
||
| 164 | // Handler: CraftVariable::EVENT_INIT |
||
| 165 | Event::on( |
||
| 166 | CraftVariable::class, |
||
| 167 | CraftVariable::EVENT_INIT, |
||
| 168 | static function(Event $event) { |
||
| 169 | /** @var CraftVariable $variable */ |
||
| 170 | $variable = $event->sender; |
||
| 171 | $variable->set('twigpack', ManifestVariable::class); |
||
| 172 | } |
||
| 173 | ); |
||
| 174 | // Handler: Plugins::EVENT_AFTER_INSTALL_PLUGIN |
||
| 175 | Event::on( |
||
| 176 | Plugins::class, |
||
| 177 | Plugins::EVENT_AFTER_INSTALL_PLUGIN, |
||
| 178 | function(PluginEvent $event) { |
||
| 179 | if ($event->plugin === $this) { |
||
| 180 | // Invalidate our caches after we've been installed |
||
| 181 | $this->clearAllCaches(); |
||
| 182 | } |
||
| 183 | } |
||
| 184 | ); |
||
| 185 | // Handler: ClearCaches::EVENT_REGISTER_CACHE_OPTIONS |
||
| 186 | Event::on( |
||
| 187 | ClearCaches::class, |
||
| 188 | ClearCaches::EVENT_REGISTER_CACHE_OPTIONS, |
||
| 189 | function(RegisterCacheOptionsEvent $event) { |
||
| 190 | Craft::debug( |
||
| 191 | 'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS', |
||
| 192 | __METHOD__ |
||
| 193 | ); |
||
| 194 | // Register our caches for the Clear Cache Utility |
||
| 195 | $event->options = array_merge( |
||
| 196 | $event->options, |
||
| 197 | $this->customAdminCpCacheOptions() |
||
| 198 | ); |
||
| 199 | } |
||
| 200 | ); |
||
| 201 | // Clears cache after craft cloud/up is run, which Craft Cloud runs on deploy |
||
| 202 | // Handler: UpController::EVENT_AFTER_UP |
||
| 203 | if (class_exists(UpController::class)) { |
||
| 204 | Event::on( |
||
| 205 | UpController::class, |
||
| 206 | UpController::EVENT_AFTER_UP, |
||
| 207 | function (CancelableEvent $event) { |
||
| 208 | $this->clearAllCaches(); |
||
| 209 | } |
||
| 210 | ); |
||
| 211 | } |
||
| 212 | |||
| 213 | // delay attaching event handler to the view component after it is fully configured |
||
| 214 | $app = Craft::$app; |
||
| 215 | if ($app->getConfig()->getGeneral()->devMode) { |
||
| 216 | $app->on(Application::EVENT_BEFORE_REQUEST, function() use ($app) { |
||
| 217 | $app->getView()->on(View::EVENT_END_BODY, [$this, 'injectErrorEntry']); |
||
| 218 | }); |
||
| 247 |