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