| Conditions | 2 |
| Paths | 2 |
| Total Lines | 52 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| 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 |
||
| 86 | public function init() |
||
| 87 | { |
||
| 88 | parent::init(); |
||
| 89 | self::$plugin = $this; |
||
| 90 | |||
| 91 | // Configure our Vite service with the settings |
||
| 92 | $settings = $this->getSettings(); |
||
| 93 | if ($settings) { |
||
| 94 | $settingsAttrs = $settings->getAttributes(); |
||
| 95 | $viteAttrs = $this->vite->getAttributes(); |
||
| 96 | Craft::configure($this->vite, array_intersect_key( |
||
| 97 | $settingsAttrs, |
||
| 98 | $viteAttrs |
||
| 99 | )); |
||
| 100 | } |
||
| 101 | // Register our variable |
||
| 102 | Event::on( |
||
| 103 | CraftVariable::class, |
||
| 104 | CraftVariable::EVENT_INIT, |
||
| 105 | function (Event $event) { |
||
| 106 | /** @var CraftVariable $variable */ |
||
| 107 | $variable = $event->sender; |
||
| 108 | $variable->set('vite', [ |
||
| 109 | 'class' => ViteVariable::class, |
||
| 110 | 'viteService' => $this->vite, |
||
| 111 | ]); |
||
| 112 | } |
||
| 113 | ); |
||
| 114 | // Handler: ClearCaches::EVENT_REGISTER_CACHE_OPTIONS |
||
| 115 | Event::on( |
||
| 116 | ClearCaches::class, |
||
| 117 | ClearCaches::EVENT_REGISTER_CACHE_OPTIONS, |
||
| 118 | function (RegisterCacheOptionsEvent $event) { |
||
| 119 | Craft::debug( |
||
| 120 | 'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS', |
||
| 121 | __METHOD__ |
||
| 122 | ); |
||
| 123 | // Register our caches for the Clear Cache Utility |
||
| 124 | $event->options = array_merge( |
||
| 125 | $event->options, |
||
| 126 | $this->customAdminCpCacheOptions() |
||
| 127 | ); |
||
| 128 | } |
||
| 129 | ); |
||
| 130 | // Log that the plugin has loaded |
||
| 131 | Craft::info( |
||
| 132 | Craft::t( |
||
| 133 | 'vite', |
||
| 134 | '{name} plugin loaded', |
||
| 135 | ['name' => $this->name] |
||
| 136 | ), |
||
| 137 | __METHOD__ |
||
| 138 | ); |
||
| 178 |