Tutorial::attributeNames()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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