Passed
Pull Request — master (#19)
by
unknown
01:50
created

Player   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 159
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 7
dl 0
loc 159
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 38 6
1
<?php
2
3
namespace ClashApi\Models
4
{
5
    use ClashApi\Models\Achievement;
6
    use ClashApi\Models\Troop;
7
    use ClashApi\Models\Heroe;
8
    use ClashApi\Models\Spell;
9
10
    class Player
11
    {
12
        /**
13
         * @var string
14
         */
15
        public $tag;
16
17
        /**
18
         * @var string
19
         */
20
        public $name;
21
        
22
        /**
23
         * @var int
24
         */
25
        public $expLevel;
26
        
27
        /**
28
         * @var int
29
         */
30
        public $trophies;
31
        
32
        /**
33
         * @var int
34
         */
35
        public $bestTrophies;
36
        
37
        /**
38
         * @var int
39
         */
40
        public $warStars;
41
        
42
        /**
43
         * @var int
44
         */
45
        public $attackWins;
46
        
47
        /**
48
         * @var int
49
         */
50
        public $defenseWins;
51
        
52
        /**
53
         * @var int
54
         */
55
        public $builderHallLevel;
56
        
57
        /**
58
         * @var int
59
         */
60
        public $versusTrophies;
61
        
62
        /**
63
         * @var int
64
         */
65
        public $bestVersusTrophies;
66
        
67
        /**
68
         * @var int
69
         */
70
        public $versusBattleWins;
71
72
        /**
73
         * @var string
74
         */
75
        public $role;
76
        
77
        /**
78
         * @var int
79
         */
80
        public $donations;
81
        
82
        /**
83
         * @var int
84
         */
85
        public $townHallLevel;
86
        
87
        /**
88
         * @var int
89
         */
90
        public $donationsReceived;
91
        
92
        /**
93
         * @var Clan
94
         */
95
        public $clan;
96
97
        /**
98
         * @var League
99
         */
100
        public $league;
101
102
        /**
103
         * @var array of Achievement objects
104
         */
105
        public $achievements = array();
106
107
        /**
108
         * @var int
109
         */
110
        public $versusBattleWinCount;
111
112
        /**
113
         * @var array of Troop objects
114
         */
115
        public $troops = array();
116
117
        /**
118
         * @var array of Heroe objects
119
         */
120
        public $heroes = array();
121
122
        /**
123
         * @var array of Spell objects
124
         */
125
        public $spells = array();
126
127
        /**
128
         * @param stdClass
129
         */
130
        public function __construct($stdClass)
131
        {
132
            $this->tag                = $stdClass->tag;
133
            $this->name               = $stdClass->name;
134
            $this->expLevel           = $stdClass->expLevel;
135
            $this->league             = new League($stdClass->league);
136
            $this->trophies           = $stdClass->trophies;
137
            $this->versusTrophies     = $stdClass->versusTrophies;
138
            $this->attackWins         = $stdClass->attackWins;
139
            $this->defenseWins        = $stdClass->defenseWins;
140
            $this->clan               = new Clan($stdClass->clan);
141
            $this->bestTrophies       = $stdClass->bestTrophies;
142
            $this->donations          = $stdClass->donations;
143
            $this->donationsReceived  = $stdClass->donationsReceived;
144
            $this->warStars           = $stdClass->warStars;
145
            $this->role               = $stdClass->role;
146
            $this->townHallLevel      = $stdClass->townHallLevel;
147
            $this->builderHallLevel   = $stdClass->builderHallLevel;
148
            $this->bestVersusTrophies = $stdClass->bestVersusTrophies;
149
            $this->versusBattleWins   = $stdClass->versusBattleWins;
150
151
            if ( isset($stdClass->legendStatistics) )
152
                $this->legendStatistics = new LegendStatistics($stdClass->legendStatistics);
0 ignored issues
show
Bug introduced by
The property legendStatistics does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
153
            
154
            foreach ($stdClass->achievements as $achievement)
155
                array_push($this->achievements, new Achievement($achievement));
156
            
157
            $this->versusBattleWinCount = $stdClass->versusBattleWinCount;
158
            
159
            foreach ($stdClass->troops as $troop)
160
                array_push($this->troops, new Troop($troop));
161
162
            foreach ($stdClass->heroes as $heroe)
163
                array_push($this->heroes, new Heroe($heroe));
164
165
            foreach ($stdClass->spells as $spell)
166
                array_push($this->spells, new Spell($spell));
167
        }
168
    }
169
}