| Conditions | 2 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| 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 |
||
| 75 | public function init() |
||
| 76 | { |
||
| 77 | parent::init(); |
||
| 78 | self::$plugin = $this; |
||
| 79 | |||
| 80 | // Handler: Elements::EVENT_AFTER_SAVE_ELEMENT |
||
| 81 | Event::on( |
||
| 82 | Elements::class, |
||
| 83 | Elements::EVENT_AFTER_SAVE_ELEMENT, |
||
| 84 | function (ElementEvent $event) { |
||
| 85 | Craft::debug( |
||
| 86 | 'Elements::EVENT_AFTER_SAVE_ELEMENT', |
||
| 87 | __METHOD__ |
||
| 88 | ); |
||
| 89 | /** @var Element $element */ |
||
| 90 | $element = $event->element; |
||
| 91 | // Only bust the cache if it's not certain excluded element types |
||
| 92 | if ($this->shouldBustCache($element)) { |
||
| 93 | Craft::debug( |
||
| 94 | 'Cache busted due to saving: ' . get_class($element) . ' - ' . $element->title, |
||
| 95 | __METHOD__ |
||
| 96 | ); |
||
| 97 | FastcgiCacheBust::$plugin->cache->clearAll(); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | ); |
||
| 101 | // Handler: TemplateCaches::EVENT_AFTER_DELETE_CACHES |
||
| 102 | Event::on( |
||
| 103 | TemplateCaches::class, |
||
| 104 | TemplateCaches::EVENT_AFTER_DELETE_CACHES, |
||
| 105 | static function (DeleteTemplateCachesEvent $event) { |
||
| 106 | FastcgiCacheBust::$plugin->cache->clearAll(); |
||
| 107 | } |
||
| 108 | ); |
||
| 109 | // Handler: ClearCaches::EVENT_REGISTER_CACHE_OPTIONS |
||
| 110 | Event::on( |
||
| 111 | ClearCaches::class, |
||
| 112 | ClearCaches::EVENT_REGISTER_CACHE_OPTIONS, |
||
| 113 | static function (RegisterCacheOptionsEvent $event) { |
||
| 114 | $event->options[] = [ |
||
| 115 | 'key' => 'fastcgi-cache-bust', |
||
| 116 | 'label' => Craft::t('fastcgi-cache-bust', 'FastCGI Cache'), |
||
| 117 | 'action' => function () { |
||
| 118 | FastcgiCacheBust::$plugin->cache->clearAll(); |
||
| 119 | }, |
||
| 120 | ]; |
||
| 121 | } |
||
| 122 | ); |
||
| 123 | |||
| 124 | Craft::info( |
||
| 125 | Craft::t( |
||
| 126 | 'fastcgi-cache-bust', |
||
| 127 | '{name} plugin loaded', |
||
| 128 | ['name' => $this->name] |
||
| 129 | ), |
||
| 130 | __METHOD__ |
||
| 131 | ); |
||
| 183 |