| Conditions | 5 |
| Paths | 9 |
| Total Lines | 64 |
| Code Lines | 43 |
| 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 |
||
| 9 | public function actionList($id = 1) |
||
| 10 | { |
||
| 11 | $location = new Location(); |
||
| 12 | $location->setId($id); |
||
| 13 | if (!$location->isVisited()) { |
||
| 14 | Yii::app()->player->model->rewriteAttributes(['last_location'=>1]); |
||
| 15 | $this->render('not_visited'); |
||
| 16 | return false; |
||
| 17 | } |
||
| 18 | |||
| 19 | $location->setActive(); |
||
| 20 | |||
| 21 | //list missions |
||
| 22 | $location->fetchRoutine(); |
||
| 23 | $location->fetchMissions(); |
||
| 24 | |||
| 25 | //complete selected mission |
||
| 26 | $mission_id = Yii::app()->request->getPost('mission_id', 0); |
||
|
|
|||
| 27 | $completedId = 0; |
||
| 28 | $error = ''; |
||
| 29 | if ($mission_id) { |
||
| 30 | $error = ''; |
||
| 31 | try { |
||
| 32 | $locAction = new LocationAction(); |
||
| 33 | $locAction->location = $location; |
||
| 34 | $locAction->completeMission($mission_id); |
||
| 35 | $completedId = $locAction->completedId; |
||
| 36 | } catch (CFlashException $e) { |
||
| 37 | $error = $e->getMessage(); |
||
| 38 | } |
||
| 39 | } |
||
| 40 | |||
| 41 | //name of location |
||
| 42 | $name = [ |
||
| 43 | 'location' => $location->getName(), |
||
| 44 | 'county' => $location->getCounty(), |
||
| 45 | ]; |
||
| 46 | |||
| 47 | //navigation from current location |
||
| 48 | $nav = $location->getNavigationLinks(); |
||
| 49 | |||
| 50 | //tutorial |
||
| 51 | $tutorialToShow = 0; |
||
| 52 | if ($id==1) { |
||
| 53 | //only in first location |
||
| 54 | $tutorial = new Tutorial; |
||
| 55 | $tutorial->state = Yii::app()->player->model->tutorial_mission; |
||
| 56 | $tutorial->location = $location; |
||
| 57 | $tutorialToShow = $tutorial->descriptionToShow; |
||
| 58 | } |
||
| 59 | $this->render('index', [ |
||
| 60 | 'location' => $location, |
||
| 61 | 'name' => $name, |
||
| 62 | 'missions'=>$location->missions, |
||
| 63 | 'missionTypeList'=>$location->missionTypes, |
||
| 64 | 'nav' => $nav, |
||
| 65 | 'mission_id'=>$mission_id, |
||
| 66 | 'completedId'=>$completedId, |
||
| 67 | 'routine'=>$location->routineStars, |
||
| 68 | 'tutorialToShow'=>$tutorialToShow, |
||
| 69 | 'error'=>$error, |
||
| 70 | ]); |
||
| 71 | |||
| 72 | } |
||
| 73 | |||
| 109 |
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.