Conditions | 3 |
Paths | 2 |
Total Lines | 62 |
Code Lines | 36 |
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 |
||
131 | protected function installEventListeners() |
||
132 | { |
||
133 | // Remember the name of the currently rendering template |
||
134 | // Handler: View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE |
||
135 | Event::on( |
||
136 | View::class, |
||
137 | View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE, |
||
138 | function (TemplateEvent $event) { |
||
139 | self::$templateName = $event->template; |
||
140 | } |
||
141 | ); |
||
142 | // Handler: CraftVariable::EVENT_INIT |
||
143 | Event::on( |
||
144 | CraftVariable::class, |
||
145 | CraftVariable::EVENT_INIT, |
||
146 | function (Event $event) { |
||
147 | /** @var CraftVariable $variable */ |
||
148 | $variable = $event->sender; |
||
149 | $variable->set('twigpack', ManifestVariable::class); |
||
150 | } |
||
151 | ); |
||
152 | // Handler: TemplateCaches::EVENT_AFTER_DELETE_CACHES |
||
153 | Event::on( |
||
154 | TemplateCaches::class, |
||
155 | TemplateCaches::EVENT_AFTER_DELETE_CACHES, |
||
|
|||
156 | function (DeleteTemplateCachesEvent $event) { |
||
157 | // Invalidate the caches when template caches are deleted |
||
158 | $this->clearAllCaches(); |
||
159 | } |
||
160 | ); |
||
161 | // Handler: Plugins::EVENT_AFTER_INSTALL_PLUGIN |
||
162 | Event::on( |
||
163 | Plugins::class, |
||
164 | Plugins::EVENT_AFTER_INSTALL_PLUGIN, |
||
165 | function (PluginEvent $event) { |
||
166 | if ($event->plugin === $this) { |
||
167 | // Invalidate our caches after we've been installed |
||
168 | $this->clearAllCaches(); |
||
169 | } |
||
170 | } |
||
171 | ); |
||
172 | // Handler: ClearCaches::EVENT_REGISTER_CACHE_OPTIONS |
||
173 | Event::on( |
||
174 | ClearCaches::class, |
||
175 | ClearCaches::EVENT_REGISTER_CACHE_OPTIONS, |
||
176 | function (RegisterCacheOptionsEvent $event) { |
||
177 | Craft::debug( |
||
178 | 'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS', |
||
179 | __METHOD__ |
||
180 | ); |
||
181 | // Register our caches for the Clear Cache Utility |
||
182 | $event->options = array_merge( |
||
183 | $event->options, |
||
184 | $this->customAdminCpCacheOptions() |
||
185 | ); |
||
186 | } |
||
187 | ); |
||
188 | // delay attaching event handler to the view component after it is fully configured |
||
189 | $app = Craft::$app; |
||
190 | if ($app->getConfig()->getGeneral()->devMode) { |
||
191 | $app->on(Application::EVENT_BEFORE_REQUEST, function () use ($app) { |
||
192 | $app->getView()->on(View::EVENT_END_BODY, [$this, 'injectErrorEntry']); |
||
193 | }); |
||
222 |
This class constant has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.