| Conditions | 8 |
| Paths | 4 |
| Total Lines | 53 |
| Code Lines | 33 |
| 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 |
||
| 171 | protected function installEventHandlers() |
||
| 172 | { |
||
| 173 | $settings = $this->getSettings(); |
||
| 174 | // Handler: Assets::EVENT_GET_THUMB_PATH |
||
| 175 | Event::on( |
||
| 176 | Assets::class, |
||
| 177 | Assets::EVENT_GET_THUMB_PATH, |
||
| 178 | function (AssetThumbEvent $event) { |
||
| 179 | Craft::debug( |
||
| 180 | 'Assets::EVENT_GET_THUMB_PATH', |
||
| 181 | __METHOD__ |
||
| 182 | ); |
||
| 183 | /** @var Asset $asset */ |
||
| 184 | $asset = $event->asset; |
||
| 185 | if (AssetsHelper::getFileKindByExtension($asset->filename) === Asset::KIND_VIDEO) { |
||
| 186 | $path = Transcoder::$plugin->transcode->handleGetAssetThumbPath($event); |
||
| 187 | if (!empty($path)) { |
||
| 188 | $event->path = $path; |
||
| 189 | } |
||
| 190 | } |
||
| 191 | } |
||
| 192 | ); |
||
| 193 | if ($settings->clearCaches) { |
||
| 194 | // Add the Transcode path to the list of things the Clear Caches tool can delete. |
||
| 195 | Event::on( |
||
| 196 | ClearCaches::class, |
||
| 197 | ClearCaches::EVENT_REGISTER_CACHE_OPTIONS, |
||
| 198 | function (RegisterCacheOptionsEvent $event) { |
||
| 199 | $event->options[] = [ |
||
| 200 | 'key' => 'transcoder', |
||
| 201 | 'label' => Craft::t('transcoder', 'Transcoder caches'), |
||
| 202 | 'action' => [$this, 'clearAllCaches'], |
||
| 203 | ]; |
||
| 204 | } |
||
| 205 | ); |
||
| 206 | } |
||
| 207 | // Handler: Plugins::EVENT_AFTER_INSTALL_PLUGIN |
||
| 208 | Event::on( |
||
| 209 | Plugins::class, |
||
| 210 | Plugins::EVENT_AFTER_INSTALL_PLUGIN, |
||
| 211 | function (PluginEvent $event) { |
||
| 212 | if ($event->plugin === $this) { |
||
| 213 | $request = Craft::$app->getRequest(); |
||
| 214 | if ($request->isCpRequest) { |
||
| 215 | Craft::$app->getResponse()->redirect(UrlHelper::cpUrl('transcoder/welcome'))->send(); |
||
| 216 | } |
||
| 217 | } |
||
| 218 | } |
||
| 219 | ); |
||
| 220 | $request = Craft::$app->getRequest(); |
||
| 221 | // Install only for non-console site requests |
||
| 222 | if ($request->getIsSiteRequest() && !$request->getIsConsoleRequest()) { |
||
| 223 | $this->installSiteEventListeners(); |
||
| 224 | } |
||
| 261 |