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 |
||
84 | public function init() |
||
85 | { |
||
86 | parent::init(); |
||
87 | self::$plugin = $this; |
||
88 | |||
89 | // Handler: Elements::EVENT_AFTER_SAVE_ELEMENT |
||
90 | Event::on( |
||
91 | Elements::class, |
||
92 | Elements::EVENT_AFTER_SAVE_ELEMENT, |
||
93 | function (ElementEvent $event) { |
||
94 | Craft::debug( |
||
95 | 'Elements::EVENT_AFTER_SAVE_ELEMENT', |
||
96 | __METHOD__ |
||
97 | ); |
||
98 | /** @var Element $element */ |
||
99 | $element = $event->element; |
||
100 | // Only bust the cache if it's not certain excluded element types |
||
101 | if ($this->shouldBustCache($element)) { |
||
102 | Craft::debug( |
||
103 | 'Cache busted due to saving: ' . get_class($element) . ' - ' . $element->title, |
||
104 | __METHOD__ |
||
105 | ); |
||
106 | FastcgiCacheBust::$plugin->cache->clearAll(); |
||
107 | } |
||
108 | } |
||
109 | ); |
||
110 | // Handler: TemplateCaches::EVENT_AFTER_DELETE_CACHES |
||
111 | Event::on( |
||
112 | TemplateCaches::class, |
||
113 | TemplateCaches::EVENT_AFTER_DELETE_CACHES, |
||
114 | static function (DeleteTemplateCachesEvent $event) { |
||
115 | FastcgiCacheBust::$plugin->cache->clearAll(); |
||
116 | } |
||
117 | ); |
||
118 | // Handler: ClearCaches::EVENT_REGISTER_CACHE_OPTIONS |
||
119 | Event::on( |
||
120 | ClearCaches::class, |
||
121 | ClearCaches::EVENT_REGISTER_CACHE_OPTIONS, |
||
122 | static function (RegisterCacheOptionsEvent $event) { |
||
123 | $event->options[] = [ |
||
124 | 'key' => 'fastcgi-cache-bust', |
||
125 | 'label' => Craft::t('fastcgi-cache-bust', 'FastCGI Cache'), |
||
126 | 'action' => function () { |
||
127 | FastcgiCacheBust::$plugin->cache->clearAll(); |
||
128 | }, |
||
129 | ]; |
||
130 | } |
||
131 | ); |
||
132 | |||
133 | Craft::info( |
||
134 | Craft::t( |
||
135 | 'fastcgi-cache-bust', |
||
136 | '{name} plugin loaded', |
||
137 | ['name' => $this->name] |
||
138 | ), |
||
139 | __METHOD__ |
||
140 | ); |
||
192 |