| Conditions | 15 |
| Paths | 14 |
| Total Lines | 51 |
| Code Lines | 36 |
| 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 |
||
| 19 | public function onBeforeInit() |
||
| 20 | { |
||
| 21 | if(Security::getCurrentUser()) { |
||
| 22 | return; |
||
| 23 | } |
||
| 24 | if (Versioned::LIVE !== Versioned::get_stage()) { |
||
| 25 | return; |
||
| 26 | } |
||
| 27 | /** PageController|ControllerExtension $owner */ |
||
| 28 | $owner = $this->getOwner(); |
||
| 29 | if ($owner instanceof ContentController) { |
||
| 30 | $extend = $owner->extend('updateCacheControl'); |
||
| 31 | if($extend) { |
||
| 32 | return; |
||
| 33 | } |
||
| 34 | $sc = SiteConfig::current_site_config(); |
||
| 35 | if(! $sc->HasCaching) { |
||
| 36 | return; |
||
| 37 | } |
||
| 38 | $request = $owner->getRequest(); |
||
| 39 | if($request->param('Action')) { |
||
| 40 | return; |
||
| 41 | } |
||
| 42 | if($request->param('ID')) { |
||
| 43 | return; |
||
| 44 | } |
||
| 45 | if($request->isAjax()) { |
||
| 46 | return; |
||
| 47 | } |
||
| 48 | if($request->getVar('flush')) { |
||
| 49 | return; |
||
| 50 | } |
||
| 51 | if($request->requestVars()) { |
||
| 52 | return; |
||
| 53 | } |
||
| 54 | $dataRecord = $owner->data(); |
||
| 55 | if (empty($dataRecord)) { |
||
| 56 | return; |
||
| 57 | } |
||
| 58 | if($dataRecord->NeverCachePublicly) { |
||
| 59 | HTTPCacheControlMiddleware::singleton() |
||
| 60 | ->disableCache() |
||
| 61 | ; |
||
| 62 | return; |
||
| 63 | } |
||
| 64 | $cacheTime = (int) ($dataRecord->PublicCacheDurationInSeconds ?: $sc->PublicCacheDurationInSeconds); |
||
| 65 | if($cacheTime > 0) { |
||
| 66 | return HTTPCacheControlMiddleware::singleton() |
||
| 67 | ->enableCache() |
||
| 68 | ->setMaxAge($cacheTime) |
||
| 69 | ->publicCache(true) |
||
| 70 | ; |
||
| 75 |