Passed
Push — master ( 1107f1...a96017 )
by Peter
34s
created

Participant   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 229
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 98.68%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 229
ccs 75
cts 76
cp 0.9868
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 49 1
A createFromArray() 0 58 2
1
<?php
2
3
namespace PtrTn\Battlerite\Dto\Match;
4
5
use Webmozart\Assert\Assert;
6
7
/**
8
 * @SuppressWarnings(PHPMD.TooManyFields)
9
 */
10
class Participant
11
{
12
    /**
13
     * @var string
14
     */
15
    public $type;
16
17
    /**
18
     * @var string
19
     */
20
    public $id;
21
22
    /**
23
     * @var string
24
     */
25
    public $actor;
26
27
    /**
28
     * @var string
29
     */
30
    public $shardId;
31
32
    /**
33
     * @var int
34
     */
35
    public $abilityUses;
36
37
    /**
38
     * @var int
39
     */
40
    public $attachment;
41
42
    /**
43
     * @var int
44
     */
45
    public $damageDone;
46
47
    /**
48
     * @var int
49
     */
50
    public $damageReceived;
51
52
    /**
53
     * @var int
54
     */
55
    public $deaths;
56
57
    /**
58
     * @var int
59
     */
60
    public $disablesDone;
61
62
    /**
63
     * @var int
64
     */
65
    public $disablesReceived;
66
67
    /**
68
     * @var int
69
     */
70
    public $emote;
71
72
    /**
73
     * @var int
74
     */
75
    public $energyGained;
76
77
    /**
78
     * @var int
79
     */
80
    public $energyUsed;
81
82
    /**
83
     * @var int
84
     */
85
    public $healingDone;
86
87
    /**
88
     * @var int
89
     */
90
    public $healingReceived;
91
92
    /**
93
     * @var int
94
     */
95
    public $kills;
96
97
    /**
98
     * @var int
99
     */
100
    public $mount;
101
102
    /**
103
     * @var int
104
     */
105
    public $outfit;
106
107
    /**
108
     * @var int
109
     */
110
    public $score;
111
112
    /**
113
     * @var int
114
     */
115
    public $side;
116
117
    /**
118
     * @var int
119
     */
120
    public $timeAlive;
121
122
    /**
123
     * @var string
124
     */
125
    public $userID;
126
127
    /**
128
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
129
     */
130 7
    private function __construct(
131
        string $type,
132
        string $id,
133
        string $actor,
134
        string $shardId,
135
        int $abilityUses,
136
        int $attachment,
137
        int $damageDone,
138
        int $damageReceived,
139
        int $deaths,
140
        int $disablesDone,
141
        int $disablesReceived,
142
        int $emote,
143
        int $energyGained,
144
        int $energyUsed,
145
        int $healingDone,
146
        int $healingReceived,
147
        int $kills,
148
        int $mount,
149
        int $outfit,
150
        int $score,
151
        int $side,
152
        int $timeAlive,
153
        string $userID
154
    ) {
155 7
        $this->type = $type;
156 7
        $this->id = $id;
157 7
        $this->actor = $actor;
158 7
        $this->shardId = $shardId;
159 7
        $this->abilityUses = $abilityUses;
160 7
        $this->attachment = $attachment;
161 7
        $this->damageDone = $damageDone;
162 7
        $this->damageReceived = $damageReceived;
163 7
        $this->deaths = $deaths;
164 7
        $this->disablesDone = $disablesDone;
165 7
        $this->disablesReceived = $disablesReceived;
166 7
        $this->emote = $emote;
167 7
        $this->energyGained = $energyGained;
168 7
        $this->energyUsed = $energyUsed;
169 7
        $this->healingDone = $healingDone;
170 7
        $this->healingReceived = $healingReceived;
171 7
        $this->kills = $kills;
172 7
        $this->mount = $mount;
173 7
        $this->outfit = $outfit;
174 7
        $this->score = $score;
175 7
        $this->side = $side;
176 7
        $this->timeAlive = $timeAlive;
177 7
        $this->userID = $userID;
178 7
    }
179
180 7
    public static function createFromArray(array $participant): self
181
    {
182 7
        Assert::string($participant['type']);
183 7
        Assert::string($participant['id']);
184 7
        Assert::string($participant['attributes']['actor']);
185 7
        Assert::string($participant['attributes']['shardId']);
186 7
        Assert::integer($participant['attributes']['stats']['abilityUses']);
187 7
        Assert::integer($participant['attributes']['stats']['attachment']);
188 7
        Assert::integer($participant['attributes']['stats']['damageDone']);
189 7
        Assert::integer($participant['attributes']['stats']['damageReceived']);
190 7
        Assert::integer($participant['attributes']['stats']['deaths']);
191 7
        Assert::integer($participant['attributes']['stats']['disablesDone']);
192 7
        Assert::integer($participant['attributes']['stats']['disablesReceived']);
193 7
        Assert::integer($participant['attributes']['stats']['emote']);
194 7
        Assert::integer($participant['attributes']['stats']['energyGained']);
195 7
        Assert::integer($participant['attributes']['stats']['energyUsed']);
196 7
        Assert::integer($participant['attributes']['stats']['healingDone']);
197 7
        Assert::integer($participant['attributes']['stats']['healingReceived']);
198 7
        Assert::integer($participant['attributes']['stats']['kills']);
199 7
        Assert::integer($participant['attributes']['stats']['mount']);
200 7
        Assert::integer($participant['attributes']['stats']['outfit']);
201 7
        Assert::integer($participant['attributes']['stats']['score']);
202 7
        Assert::integer($participant['attributes']['stats']['side']);
203 7
        Assert::integer($participant['attributes']['stats']['timeAlive']);
204
205 7
        if (isset($participant['attributes']['stats']['userID'])) {
206 7
            $userId = $participant['attributes']['stats']['userID'];
207
        } else {
208
            $userId = $participant['relationships']['player']['data']['id'];
209
        }
210 7
        Assert::string($userId);
211
212 7
        return new self(
213 7
            $participant['type'],
214 7
            $participant['id'],
215 7
            $participant['attributes']['actor'],
216 7
            $participant['attributes']['shardId'],
217 7
            $participant['attributes']['stats']['abilityUses'],
218 7
            $participant['attributes']['stats']['attachment'],
219 7
            $participant['attributes']['stats']['damageDone'],
220 7
            $participant['attributes']['stats']['damageReceived'],
221 7
            $participant['attributes']['stats']['deaths'],
222 7
            $participant['attributes']['stats']['disablesDone'],
223 7
            $participant['attributes']['stats']['disablesReceived'],
224 7
            $participant['attributes']['stats']['emote'],
225 7
            $participant['attributes']['stats']['energyGained'],
226 7
            $participant['attributes']['stats']['energyUsed'],
227 7
            $participant['attributes']['stats']['healingDone'],
228 7
            $participant['attributes']['stats']['healingReceived'],
229 7
            $participant['attributes']['stats']['kills'],
230 7
            $participant['attributes']['stats']['mount'],
231 7
            $participant['attributes']['stats']['outfit'],
232 7
            $participant['attributes']['stats']['score'],
233 7
            $participant['attributes']['stats']['side'],
234 7
            $participant['attributes']['stats']['timeAlive'],
235 7
            $userId
236
        );
237
    }
238
}
239