Conditions | 12 |
Paths | 204 |
Total Lines | 115 |
Code Lines | 71 |
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 |
||
16 | public function indexAction(Request $request, Phpfastcache $phpfastcache) |
||
|
|||
17 | { |
||
18 | $pfc_test = null; |
||
19 | |||
20 | $cache = $phpfastcache->get('filecache'); |
||
21 | $cache2 = $phpfastcache->get('memcachecache'); |
||
22 | $cache3 = $phpfastcache->get('ssdbcache'); |
||
23 | $cache4 = $phpfastcache->get('sqlitecache'); |
||
24 | $cache5 = $phpfastcache->get('rediscache'); |
||
25 | $cache6 = $phpfastcache->get('mongodbcache'); |
||
26 | $cache7 = $phpfastcache->get('couchbasecache'); |
||
27 | $cache8 = $phpfastcache->get('leveldbcache'); |
||
28 | |||
29 | /** |
||
30 | * Xcache and APC cannot coexists |
||
31 | */ |
||
32 | try{ |
||
33 | $cache9 = $phpfastcache->get('apccache'); |
||
34 | $cache10 = $phpfastcache->get('apcucache'); |
||
35 | }catch(PhpfastcacheDriverCheckException $e){ |
||
36 | $cache11 = $phpfastcache->get('xcachecache'); |
||
37 | } |
||
38 | |||
39 | $cache12 = $phpfastcache->get('devnullcache'); |
||
40 | |||
41 | |||
42 | $item = $cache->getItem('test'); |
||
43 | $item1 = $cache->getItem('test2'); |
||
44 | $item2 = $cache2->getItem('test'); |
||
45 | $item3 = $cache3->getItem('test'); |
||
46 | $item4 = $cache4->getItem('test'); |
||
47 | $item5 = $cache5->getItem('test'); |
||
48 | $item6 = $cache6->getItem('test'); |
||
49 | $item7 = $cache7->getItem('test'); |
||
50 | $item8 = $cache7->getItem('test2'); |
||
51 | $item9 = $cache8->getItem('test2'); |
||
52 | |||
53 | if(isset($cache9) && isset($cache10)) |
||
54 | { |
||
55 | $item10 = $cache9->getItem('test2'); |
||
56 | $item11 = $cache10->getItem('test2'); |
||
57 | } |
||
58 | |||
59 | if(isset($cache11)) |
||
60 | { |
||
61 | $item12 = $cache11->getItem('test2'); |
||
62 | } |
||
63 | |||
64 | $item13 = $cache12->getItem('test2'); |
||
65 | |||
66 | |||
67 | |||
68 | if ($item->isHit()) { |
||
69 | $pfc_test = $item->get(); |
||
70 | } else { |
||
71 | |||
72 | $item->set('Loaded from cache')->expiresAfter(10); |
||
73 | $item1->set('Loaded from cache2')->expiresAfter(10); |
||
74 | $item2->set('Loaded from cache +' . str_repeat('*', rand(1000, 5000)))->expiresAfter(10); |
||
75 | $item3->set('Loaded from cache +' . str_repeat('+', rand(1000, 5000)))->expiresAfter(10); |
||
76 | $item4->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
||
77 | $item5->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
||
78 | $item6->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
||
79 | $item7->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
||
80 | $item8->set('Loaded from cache2')->expiresAfter(10); |
||
81 | $item9->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
||
82 | |||
83 | if(isset($item10) && isset($item11)) |
||
84 | { |
||
85 | $item10->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
||
86 | $item11->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
||
87 | } |
||
88 | |||
89 | if(isset($item12)) |
||
90 | { |
||
91 | $item12->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
||
92 | } |
||
93 | |||
94 | $item13->set('Loaded from cache +' . str_repeat('-', rand(1000, 5000)))->expiresAfter(10); |
||
95 | |||
96 | |||
97 | $cache->save($item); |
||
98 | $cache->save($item1); |
||
99 | $cache2->save($item2); |
||
100 | $cache3->save($item3); |
||
101 | $cache4->save($item4); |
||
102 | $cache5->save($item5); |
||
103 | $cache6->save($item6); |
||
104 | $cache7->save($item7); |
||
105 | $cache7->save($item8); |
||
106 | $cache8->save($item9); |
||
107 | |||
108 | if(isset($cache9) && isset($cache10)) |
||
109 | { |
||
110 | $cache9->save($item10); |
||
111 | $cache10->save($item11); |
||
112 | } |
||
113 | |||
114 | if(isset($cache11)) |
||
115 | { |
||
116 | $cache11->save($item12); |
||
117 | } |
||
118 | |||
119 | $cache12->save($item13); |
||
120 | |||
121 | |||
122 | $pfc_test = 'Not loaded from cache'; |
||
123 | } |
||
124 | |||
125 | // replace this example code with whatever you need |
||
126 | return $this->render('default/index.html.twig', [ |
||
127 | 'pfc_test' => $pfc_test, |
||
128 | 'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..'), |
||
129 | ]); |
||
130 | } |
||
131 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.