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 |
||
103 | protected function installEventListeners() |
||
104 | { |
||
105 | // Remember the name of the currently rendering template |
||
106 | // Handler: View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE |
||
107 | Event::on( |
||
108 | View::class, |
||
109 | View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE, |
||
110 | function (TemplateEvent $event) { |
||
111 | self::$templateName = $event->template; |
||
112 | } |
||
113 | ); |
||
114 | // Handler: CraftVariable::EVENT_INIT |
||
115 | Event::on( |
||
116 | CraftVariable::class, |
||
117 | CraftVariable::EVENT_INIT, |
||
118 | function (Event $event) { |
||
119 | /** @var CraftVariable $variable */ |
||
120 | $variable = $event->sender; |
||
121 | $variable->set('twigpack', ManifestVariable::class); |
||
122 | } |
||
123 | ); |
||
124 | // Handler: TemplateCaches::EVENT_AFTER_DELETE_CACHES |
||
125 | Event::on( |
||
126 | TemplateCaches::class, |
||
127 | TemplateCaches::EVENT_AFTER_DELETE_CACHES, |
||
128 | function (DeleteTemplateCachesEvent $event) { |
||
|
|||
129 | // Invalidate the caches when template caches are deleted |
||
130 | $this->clearAllCaches(); |
||
131 | } |
||
132 | ); |
||
133 | // Handler: Plugins::EVENT_AFTER_INSTALL_PLUGIN |
||
134 | Event::on( |
||
135 | Plugins::class, |
||
136 | Plugins::EVENT_AFTER_INSTALL_PLUGIN, |
||
137 | function (PluginEvent $event) { |
||
138 | if ($event->plugin === $this) { |
||
139 | // Invalidate our caches after we've been installed |
||
140 | $this->clearAllCaches(); |
||
141 | } |
||
142 | } |
||
143 | ); |
||
144 | // Handler: ClearCaches::EVENT_REGISTER_CACHE_OPTIONS |
||
145 | Event::on( |
||
146 | ClearCaches::class, |
||
147 | ClearCaches::EVENT_REGISTER_CACHE_OPTIONS, |
||
148 | function (RegisterCacheOptionsEvent $event) { |
||
149 | Craft::debug( |
||
150 | 'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS', |
||
151 | __METHOD__ |
||
152 | ); |
||
153 | // Register our caches for the Clear Cache Utility |
||
154 | $event->options = array_merge( |
||
155 | $event->options, |
||
156 | $this->customAdminCpCacheOptions() |
||
157 | ); |
||
158 | } |
||
159 | ); |
||
160 | // delay attaching event handler to the view component after it is fully configured |
||
161 | $app = Craft::$app; |
||
162 | if ($app->getConfig()->getGeneral()->devMode) { |
||
163 | $app->on(Application::EVENT_BEFORE_REQUEST, function () use ($app) { |
||
164 | $app->getView()->on(View::EVENT_END_BODY, [$this, 'injectErrorEntry']); |
||
165 | }); |
||
214 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.