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