Passed
Pull Request — master (#20)
by
unknown
01:59
created

Player   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 149
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 8
dl 0
loc 149
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 PoLaKoSz\CoC_API\Models
4
{
5
    use PoLaKoSz\CoC_API\Models\Achievement;
6
    use PoLaKoSz\CoC_API\Models\MinimalPlayer;
7
    use PoLaKoSz\CoC_API\Models\Heroe;
8
    use PoLaKoSz\CoC_API\Models\Troop;
9
    use PoLaKoSz\CoC_API\Models\Spell;
10
11
    class Player extends MinimalPlayer
12
    {
13
        /**
14
         * @var int
15
         */
16
        public $expLevel;
17
        
18
        /**
19
         * @var int
20
         */
21
        public $trophies;
22
        
23
        /**
24
         * @var int
25
         */
26
        public $bestTrophies;
27
        
28
        /**
29
         * @var int
30
         */
31
        public $warStars;
32
        
33
        /**
34
         * @var int
35
         */
36
        public $attackWins;
37
        
38
        /**
39
         * @var int
40
         */
41
        public $defenseWins;
42
        
43
        /**
44
         * @var int
45
         */
46
        public $builderHallLevel;
47
        
48
        /**
49
         * @var int
50
         */
51
        public $versusTrophies;
52
        
53
        /**
54
         * @var int
55
         */
56
        public $bestVersusTrophies;
57
        
58
        /**
59
         * @var int
60
         */
61
        public $versusBattleWins;
62
63
        /**
64
         * @var string
65
         */
66
        public $role;
67
        
68
        /**
69
         * @var int
70
         */
71
        public $donations;
72
        
73
        /**
74
         * @var int
75
         */
76
        public $townHallLevel;
77
        
78
        /**
79
         * @var int
80
         */
81
        public $donationsReceived;
82
        
83
        /**
84
         * @var Clan
85
         */
86
        public $clan;
87
88
        /**
89
         * @var League
90
         */
91
        public $league;
92
93
        /**
94
         * @var array of Achievement objects
95
         */
96
        public $achievements = array();
97
98
        /**
99
         * @var int
100
         */
101
        public $versusBattleWinCount;
102
103
        /**
104
         * @var array of Troop objects
105
         */
106
        public $troops = array();
107
108
        /**
109
         * @var array of Heroe objects
110
         */
111
        public $heroes = array();
112
113
        /**
114
         * @var array of Spell objects
115
         */
116
        public $spells = array();
117
118
        /**
119
         * @param stdClass
120
         */
121
        public function __construct($stdClass)
122
        {
123
            parent::__construct( $stdClass );
124
            
125
            $this->expLevel           = $stdClass->expLevel;
126
            $this->league             = new League($stdClass->league);
127
            $this->trophies           = $stdClass->trophies;
128
            $this->versusTrophies     = $stdClass->versusTrophies;
129
            $this->attackWins         = $stdClass->attackWins;
130
            $this->defenseWins        = $stdClass->defenseWins;
131
            $this->clan               = new Clan($stdClass->clan);
132
            $this->bestTrophies       = $stdClass->bestTrophies;
133
            $this->donations          = $stdClass->donations;
134
            $this->donationsReceived  = $stdClass->donationsReceived;
135
            $this->warStars           = $stdClass->warStars;
136
            $this->role               = $stdClass->role;
137
            $this->townHallLevel      = $stdClass->townHallLevel;
138
            $this->builderHallLevel   = $stdClass->builderHallLevel;
139
            $this->bestVersusTrophies = $stdClass->bestVersusTrophies;
140
            $this->versusBattleWins   = $stdClass->versusBattleWins;
141
142
            if ( isset($stdClass->legendStatistics) )
143
                $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...
144
            
145
            foreach ($stdClass->achievements as $achievement)
146
                array_push($this->achievements, new Achievement($achievement));
147
            
148
            $this->versusBattleWinCount = $stdClass->versusBattleWinCount;
149
            
150
            foreach ($stdClass->troops as $troop)
151
                array_push($this->troops, new Troop($troop));
152
153
            foreach ($stdClass->heroes as $heroe)
154
                array_push($this->heroes, new Heroe($heroe));
155
156
            foreach ($stdClass->spells as $spell)
157
                array_push($this->spells, new Spell($spell));
158
        }
159
    }
160
}