| Conditions | 11 | 
| Paths | 216 | 
| Total Lines | 56 | 
| Code Lines | 35 | 
| 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 | ||
| 81 | public function actionStore() | ||
| 82 |     { | ||
| 83 | $store = new Store; | ||
| 84 | $store->uid = Yii::app()->player->model->uid; | ||
| 85 | |||
| 86 | $r = Yii::app()->request; | ||
| 87 | |||
| 88 | $duelShield = new DuelShield(); | ||
| 89 | $duelShield->uid = $store->uid; | ||
| 90 | |||
| 91 | //duelShield | ||
| 92 |         $shield = (int)$r->getPost('shield', 0); | ||
| 93 |         try { | ||
| 94 |             if ($shield) { | ||
| 95 |                 if ($duelShield->activate($shield)) { | ||
| 96 |                     Yii::app()->user->setFlash('success', "Bekapcsoltad a párbaj-pajzsot."); | ||
| 97 | $this->redirect(['']); | ||
| 98 | } | ||
| 99 | } | ||
| 100 |         } catch (CFlashException $e) { | ||
| 101 |             Yii::app()->user->setFlash('error', $e->getMessage()); | ||
| 102 | } | ||
| 103 | |||
| 104 | //energy drink | ||
| 105 |         $energy = (int)$r->getPost('energy', 0); | ||
| 106 |         try { | ||
| 107 |             if ($energy) { | ||
| 108 |                 if ($store->refillEnergy()) { | ||
| 109 |                     Yii::app()->user->setFlash('success', "Megittál egy energiaitalt, ezáltal teljesen feltöltődtél. Remélem ízlett."); | ||
| 110 | $this->redirect(['']); | ||
| 111 | } | ||
| 112 | } | ||
| 113 |         } catch (CFlashException $e) { | ||
| 114 |             Yii::app()->user->setFlash('error', $e->getMessage()); | ||
| 115 | } | ||
| 116 | |||
| 117 | //missing set items | ||
| 118 |         $setItem = (int)$r->getPost('setItem', 0); | ||
| 119 |         try { | ||
| 120 |             if ($setItem) { | ||
| 121 |                 if ($store->buySetItem($setItem)) { | ||
| 122 |                     Yii::app()->user->setFlash('success', "Megvetted a kiválasztott szett elemet. Ilyen típusút jövő héten vásárolhatsz legközelebb."); | ||
| 123 | $this->redirect(['']); | ||
| 124 | } | ||
| 125 | } | ||
| 126 |         } catch (CFlashException $e) { | ||
| 127 |             Yii::app()->user->setFlash('error', $e->getMessage()); | ||
| 128 | } | ||
| 129 | |||
| 130 |         $this->render('store', [ | ||
| 131 | 'store'=>$store, | ||
| 132 | 'duelShield' => $duelShield, | ||
| 133 | 'shieldPrices' => $duelShield->getPrices(), | ||
| 134 |             'banner'=>(date("nd") == Yii::app()->params['smsDate']) ? Yii::app()->params['smsText'] : '', | ||
| 135 | ]); | ||
| 136 | } | ||
| 137 | |||
| 144 | 
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.