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