Tutorial::update()   C
last analyzed

Complexity

Conditions 20
Paths 48

Size

Total Lines 58
Code Lines 37

Duplication

Lines 21
Ratio 36.21 %

Importance

Changes 0
Metric Value
dl 21
loc 58
rs 6.3621
c 0
b 0
f 0
cc 20
eloc 37
nc 48
nop 0

How to fix   Long Method    Complexity   

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
/**
3
 * @property integer $state
4
 * @property integer $descriptionToShow
5
 * @property Location $location
6
 */
7
class Tutorial extends CModel
8
{
9
    private $state;
10
    private $location;
11
    private $descriptionToShow;
12
13
    public function attributeNames()
14
    {
15
        return [];
16
    }
17
18
    public function getState()
19
    {
20
        return (int)$this->state;
21
    }
22
23
    public function getDescriptionToShow()
24
    {
25
        $this->update();
26
        return (int)$this->descriptionToShow;
27
    }
28
    
29
    public function setState($state)
30
    {
31
        $this->state = (int)$state;
32
    }
33
34
    public function setLocation($location)
35
    {
36
        $this->location = $location;
37
    }
38
39
    private function update()
40
    {
41
        $player = Yii::app()->player->model;
42
        //check requirements of new state
43
        $advance = false;
44
        switch ($this->state) {
45 View Code Duplication
            case 0:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
                //teljesits 1 megbizast
47
                foreach ($this->location->missions as $mission) {
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...
48
                    if ($mission->routine > 0) {
49
                        $advance = true;
50
                    }
51
                }
52
                break;
53
            case 1:
54
                if ($player->dollar >= 10) {
55
                    $advance = true;
56
                }
57
                break;
58
            case 2:
59
                if ($player->skill_extended - $player->skill > 2) {
60
                    $advance = true;
61
                }
62
                break;
63 View Code Duplication
            case 3:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
                //1 megbizasnal 100% rutin
65
                foreach ($this->location->missions as $mission) {
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...
66
                    if ($mission->routine >= 100) {
67
                        $advance = true;
68
                    }
69
                }
70
                break;
71
            case 4:
72
                $advance = true;
73 View Code Duplication
                foreach ($this->location->missions as $mission) {
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...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
                    if (!$mission->gate && $mission->routine < 100) {
75
                        $advance = false;
76
                    }
77
                }
78
                break;
79
            case 5:
80
                if ($this->location->routine > 0) {
0 ignored issues
show
Bug introduced by
The property routine 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...
81
                    $advance = true;
82
                }
83
                break;
84
            case 6:
85
                //advance at first travel
86
        }
87
        
88
        //advance to new state
89
        if ($advance) {
90
            Yii::app()->player->model->updateAttributes(['tutorial_mission'=>1], []);
91
            $this->state++;
92
        }
93
94
        //set description
95
        $this->descriptionToShow = $this->state < 7 ? $this->state+1 : 0;
96
    }
97
}
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...
98