MissionsController::actionList()   B
last analyzed

Complexity

Conditions 5
Paths 9

Size

Total Lines 64
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 64
rs 8.6346
c 0
b 0
f 0
cc 5
eloc 43
nc 9
nop 1

How to fix   Long Method   

Long Method

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:

1
<?php
2
class MissionsController extends GameController
3
{
4
    public function actionIndex()
5
    {
6
        $this->redirect(['missions/list', 'id'=>Yii::app()->player->model->last_location]);
7
    }
8
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);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
27
        $completedId = 0;
28
        $error = '';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
29
        if ($mission_id) {
30
            $error = '';
31
            try {
32
                $locAction = new LocationAction();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
33
                $locAction->location = $location;
0 ignored issues
show
Bug introduced by
The property location cannot be accessed from this context as it is declared private in class LocationAction.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
34
                $locAction->completeMission($mission_id);
35
                $completedId = $locAction->completedId;
0 ignored issues
show
Bug introduced by
The property completedId cannot be accessed from this context as it is declared private in class LocationAction.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
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;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
55
            $tutorial->state = Yii::app()->player->model->tutorial_mission;
0 ignored issues
show
Bug introduced by
The property state cannot be accessed from this context as it is declared private in class Tutorial.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
56
            $tutorial->location = $location;
0 ignored issues
show
Bug introduced by
The property location cannot be accessed from this context as it is declared private in class Tutorial.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
57
            $tutorialToShow = $tutorial->descriptionToShow;
0 ignored issues
show
Bug introduced by
The property descriptionToShow cannot be accessed from this context as it is declared private in class Tutorial.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
58
        }
59
        $this->render('index', [
60
            'location' => $location,
61
            'name' => $name,
62
            'missions'=>$location->missions,
0 ignored issues
show
Bug introduced by
The property missions cannot be accessed from this context as it is declared private in class Location.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
63
            'missionTypeList'=>$location->missionTypes,
0 ignored issues
show
Bug introduced by
The property missionTypes cannot be accessed from this context as it is declared private in class Location.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
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
74
    public function actionMap()
75
    {
76
        $this->layout = 'fullscreen';
77
78
        $location = new Location();
79
        $visited = $location->listVisited();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
80
81
        $center = Yii::app()->params['mapCenterCoords']; //id 1
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
82
        $last = [];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
83
        $locations = [];
84
        foreach ($visited as $v) {
85
            $id = (int)$v['id'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
86
            $txtRoutine = '';
87
            if ($v['routine']) {
88
                $routine = $location->getRoutineStars($v['routine']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
89
                $txtRoutine = 'Helyszínen megszerzett rutinod: <br/>';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
90
                $txtRoutine .= $location->getRoutineImages($routine);
91
            } else {
92
                $last[] = $id;
93
            }
94
95
            $locations[] = "[{$v['position']}, '{$v['title']}', {$id}, '{$txtRoutine}']";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $v instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $id instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $txtRoutine instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
96
            if (isset($v['last'])) {
97
                $center = $v['position'];
98
            }
99
        }
100
101
        $this->render('map', [
102
            'visited'=>$visited,
103
            'locations'=>implode(",\n", $locations),
104
            'center'=>$center,
105
            'last'=>implode(', ', $last)
106
            ]);
107
    }
108
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
109