| Conditions | 2 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 35 |
| 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 |
||
| 55 | public function init() |
||
| 56 | { |
||
| 57 | parent::init(); |
||
| 58 | self::$plugin = $this; |
||
| 59 | |||
| 60 | // Handler: Elements::EVENT_AFTER_SAVE_ELEMENT |
||
| 61 | Event::on( |
||
| 62 | Elements::class, |
||
| 63 | Elements::EVENT_AFTER_SAVE_ELEMENT, |
||
| 64 | function (ElementEvent $event) { |
||
| 65 | Craft::debug( |
||
| 66 | 'Elements::EVENT_AFTER_SAVE_ELEMENT', |
||
| 67 | __METHOD__ |
||
| 68 | ); |
||
| 69 | /** @var Element $element */ |
||
| 70 | $element = $event->element; |
||
| 71 | // Only bust the cache if it's not certain excluded element types |
||
| 72 | if ($this->shouldBustCache($element)) { |
||
| 73 | Craft::debug( |
||
| 74 | 'Cache busted due to saving: '.\get_class($element).' - '.$element->title, |
||
| 75 | __METHOD__ |
||
| 76 | ); |
||
| 77 | FastcgiCacheBust::$plugin->cache->clearAll(); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | ); |
||
| 81 | // Handler: TemplateCaches::EVENT_AFTER_DELETE_CACHES |
||
| 82 | Event::on( |
||
| 83 | TemplateCaches::class, |
||
| 84 | TemplateCaches::EVENT_AFTER_DELETE_CACHES, |
||
| 85 | function (DeleteTemplateCachesEvent $event) { |
||
|
|
|||
| 86 | FastcgiCacheBust::$plugin->cache->clearAll(); |
||
| 87 | } |
||
| 88 | ); |
||
| 89 | // Handler: ClearCaches::EVENT_REGISTER_CACHE_OPTIONS |
||
| 90 | Event::on( |
||
| 91 | ClearCaches::class, |
||
| 92 | ClearCaches::EVENT_REGISTER_CACHE_OPTIONS, |
||
| 93 | function (RegisterCacheOptionsEvent $event) { |
||
| 94 | $event->options[] = [ |
||
| 95 | 'key' => 'fastcgi-cache-bust', |
||
| 96 | 'label' => Craft::t('fastcgi-cache-bust', 'FastCGI Cache'), |
||
| 97 | 'action' => function () { |
||
| 98 | FastcgiCacheBust::$plugin->cache->clearAll(); |
||
| 99 | }, |
||
| 100 | ]; |
||
| 101 | } |
||
| 102 | ); |
||
| 103 | |||
| 104 | Craft::info( |
||
| 105 | Craft::t( |
||
| 106 | 'fastcgi-cache-bust', |
||
| 107 | '{name} plugin loaded', |
||
| 108 | ['name' => $this->name] |
||
| 109 | ), |
||
| 110 | __METHOD__ |
||
| 111 | ); |
||
| 174 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.