Completed
Push — master ( b8b783...188bc3 )
by De Cramer
9s
created

Player::getCurrentTargetId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: olive
5
 * Date: 12/03/2017
6
 * Time: 16:26
7
 */
8
9
namespace eXpansion\Core\Storage\Data;
10
11
/**
12
 * All data related to a player/spectator on the server.
13
 *
14
 * @package eXpansion\Core\Storage\Data
15
 */
16
class Player
17
{
18
    /** @var string */
19
    protected $login;
20
21
    /** @var bool */
22
    protected $isConnected = true;
23
24
    /** @var string */
25
    protected $nickName;
26
27
    /** @var int */
28
    protected $playerId;
29
30
    /** @var int */
31
    protected $teamId;
32
33
    /** @var bool */
34
    protected $isInOfficialMode;
35
36
    /** @var int */
37
    protected $ladderRanking;
38
39
    /** @var int */
40
    protected $spectatorStatus;
41
42
    /** @var int */
43
    protected $flags;
44
45
    /** @var int */
46
    protected $forceSpectator;
47
48
    /** @var bool */
49
    protected $isReferee;
50
51
    /** @var bool */
52
    protected $isPodiumReady;
53
54
    /** @var bool */
55
    protected $isUsingStereoscopy;
56
57
    /** @var bool */
58
    protected $isManagedByAnOtherServer;
59
60
    /** @var bool */
61
    protected $isServer;
62
63
    /** @var bool */
64
    protected $hasPlayerSlot;
65
66
    /** @var bool */
67
    protected $isBroadcasting;
68
69
    /** @var bool */
70
    protected $hasJoinedGame = false;
71
72
    /** @var bool */
73
    protected $spectator;
74
75
    /** @var bool */
76
    protected $temporarySpectator;
77
78
    /** @var bool */
79
    protected $pureSpectator;
80
81
    /** @var bool */
82
    protected $autoTarget;
83
84
    /** @var int */
85
    protected $currentTargetId;
86
87
    /** @var string */
88
    protected $path;
89
90
    /** @var string */
91
    protected $language;
92
93
    /** @var string */
94
    protected $clientVersion;
95
96
    /** @var string */
97
    protected $clientTitleVersion;
98
99
    /** @var string */
100
    protected $iPAddress;
101
102
    /** @var int */
103
    protected $downloadRate;
104
105
    /** @var int */
106
    protected $uploadRate;
107
108
    /** @var FileDesc */
109
    protected $avatar;
110
111
    /** @var Skin[] */
112
    protected $skins;
113
114
    /** @var mixed[] */
115
    protected $ladderStats;
116
117
    /** @var int */
118
    protected $hoursSinceZoneInscription;
119
120
    /** @var string */
121
    protected $broadcasterLogin;
122
123
    /** @var string[] */
124
    protected $allies = array();
125
126
    /** @var string */
127
    protected $clubLink;
128
    /** @var int */
129
    protected $rank;
130
131
    /** @var int */
132
    protected $bestTime;
133
134
    /** @var int[] */
135
    protected $bestCheckpoints;
136
137
    /** @var int */
138
    protected $score;
139
140
    /** @var int */
141
    protected $nbrLapsFinished;
142
143
    /** @var float */
144
    protected $ladderScore;
145
146
    /**
147
     * @return boolean
148
     */
149 1
    public function isIsConnected()
150
    {
151 1
        return $this->isConnected;
152
    }
153
154
    /**
155
     * @return string
156
     */
157 2
    public function getNickName()
158
    {
159 2
        return $this->nickName;
160
    }
161
162
    /**
163
     * @return int
164
     */
165 2
    public function getPlayerId()
166
    {
167 2
        return $this->playerId;
168
    }
169
170
    /**
171
     * @return int
172
     */
173 1
    public function getTeamId()
174
    {
175 1
        return $this->teamId;
176
    }
177
178
    /**
179
     * @return boolean
180
     */
181
    public function isIsSpectator()
182
    {
183
        return $this->spectatorStatus != 0;
184
    }
185
186
    /**
187
     * @return boolean
188
     */
189 1
    public function isIsInOfficialMode()
190
    {
191 1
        return $this->isInOfficialMode;
192
    }
193
194
    /**
195
     * @return int
196
     */
197 1
    public function getLadderRanking()
198
    {
199 1
        return $this->ladderRanking;
200
    }
201
202
    /**
203
     * @return int
204
     */
205 3
    public function getSpectatorStatus()
206
    {
207 3
        return $this->spectatorStatus;
208
    }
209
210
    /**
211
     * @return int
212
     */
213 1
    public function getFlags()
214
    {
215 1
        return $this->flags;
216
    }
217
218
    /**
219
     * @return int
220
     */
221 1
    public function getForceSpectator()
222
    {
223 1
        return $this->forceSpectator;
224
    }
225
226
    /**
227
     * @return boolean
228
     */
229 1
    public function isIsReferee()
230
    {
231 1
        return $this->isReferee;
232
    }
233
234
    /**
235
     * @return boolean
236
     */
237 1
    public function isIsPodiumReady()
238
    {
239 1
        return $this->isPodiumReady;
240
    }
241
242
    /**
243
     * @return boolean
244
     */
245 1
    public function isIsUsingStereoscopy()
246
    {
247 1
        return $this->isUsingStereoscopy;
248
    }
249
250
    /**
251
     * @return boolean
252
     */
253 1
    public function isIsManagedByAnOtherServer()
254
    {
255 1
        return $this->isManagedByAnOtherServer;
256
    }
257
258
    /**
259
     * @return boolean
260
     */
261 2
    public function isIsServer()
262
    {
263 2
        return $this->isServer;
264
    }
265
266
    /**
267
     * @return boolean
268
     */
269 1
    public function isHasPlayerSlot()
270
    {
271 1
        return $this->hasPlayerSlot;
272
    }
273
274
    /**
275
     * @return boolean
276
     */
277 1
    public function isIsBroadcasting()
278
    {
279 1
        return $this->isBroadcasting;
280
    }
281
282
    /**
283
     * @return boolean
284
     */
285 1
    public function isHasJoinedGame()
286
    {
287 1
        return $this->hasJoinedGame;
288
    }
289
290
    /**
291
     * @return boolean
292
     */
293 10
    public function isSpectator()
294
    {
295 10
        return $this->spectator;
296
    }
297
298
    /**
299
     * @return boolean
300
     */
301 1
    public function isTemporarySpectator()
302
    {
303 1
        return $this->temporarySpectator;
304
    }
305
306
    /**
307
     * @return boolean
308
     */
309 1
    public function isPureSpectator()
310
    {
311 1
        return $this->pureSpectator;
312
    }
313
314
    /**
315
     * @return boolean
316
     */
317 1
    public function isAutoTarget()
318
    {
319 1
        return $this->autoTarget;
320
    }
321
322
    /**
323
     * @return int
324
     */
325 1
    public function getCurrentTargetId()
326
    {
327 1
        return $this->currentTargetId;
328
    }
329
330
    /**
331
     * @return string
332
     */
333 1
    public function getPath()
334
    {
335 1
        return $this->path;
336
    }
337
338
    /**
339
     * @return string
340
     */
341 1
    public function getLanguage()
342
    {
343 1
        return $this->language;
344
    }
345
346
    /**
347
     * @return string
348
     */
349 2
    public function getClientVersion()
350
    {
351 2
        return $this->clientVersion;
352
    }
353
354
    /**
355
     * @return string
356
     */
357 1
    public function getClientTitleVersion()
358
    {
359 1
        return $this->clientTitleVersion;
360
    }
361
362
    /**
363
     * @return string
364
     */
365 1
    public function getIPAddress()
366
    {
367 1
        return $this->iPAddress;
368
    }
369
370
    /**
371
     * @return int
372
     */
373 1
    public function getDownloadRate()
374
    {
375 1
        return $this->downloadRate;
376
    }
377
378
    /**
379
     * @return int
380
     */
381 1
    public function getUploadRate()
382
    {
383 1
        return $this->uploadRate;
384
    }
385
386
    /**
387
     * @return FileDesc
388
     */
389 1
    public function getAvatar()
390
    {
391 1
        return $this->avatar;
392
    }
393
394
    /**
395
     * @return Skin[]
396
     */
397 1
    public function getSkins()
398
    {
399 1
        return $this->skins;
400
    }
401
402
    /**
403
     * @return \mixed[]
404
     */
405 1
    public function getLadderStats()
406
    {
407 1
        return $this->ladderStats;
408
    }
409
410
    /**
411
     * @return int
412
     */
413 1
    public function getHoursSinceZoneInscription()
414
    {
415 1
        return $this->hoursSinceZoneInscription;
416
    }
417
418
    /**
419
     * @return string
420
     */
421 1
    public function getBroadcasterLogin()
422
    {
423 1
        return $this->broadcasterLogin;
424
    }
425
426
    /**
427
     * @return string[]
428
     */
429 1
    public function getAllies()
430
    {
431 1
        return $this->allies;
432
    }
433
434
    /**
435
     * @return string
436
     */
437 1
    public function getClubLink()
438
    {
439 1
        return $this->clubLink;
440
    }
441
442
    /**
443
     * @return int
444
     */
445 1
    public function getRank()
446
    {
447 1
        return $this->rank;
448
    }
449
450
    /**
451
     * @return int
452
     */
453 1
    public function getBestTime()
454
    {
455 1
        return $this->bestTime;
456
    }
457
458
    /**
459
     * @return integer[]
460
     */
461 1
    public function getBestCheckpoints()
462
    {
463 1
        return $this->bestCheckpoints;
464
    }
465
466
    /**
467
     * @return int
468
     */
469 1
    public function getScore()
470
    {
471 1
        return $this->score;
472
    }
473
474
    /**
475
     * @return int
476
     */
477 1
    public function getNbrLapsFinished()
478
    {
479 1
        return $this->nbrLapsFinished;
480
    }
481
482
    /**
483
     * @return float
484
     */
485 1
    public function getLadderScore()
486
    {
487 1
        return $this->ladderScore;
488
    }
489
490
    /**
491
     * @return string
492
     */
493 12
    public function getLogin()
494
    {
495 12
        return $this->login;
496
    }
497
498
    /**
499
     * @param \Maniaplanet\DedicatedServer\Structures\Player|array $data
500
     *
501
     * @return $this
502
     */
503 26
    function merge($data)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
504
    {
505 26
        foreach ($data as $key => $value) {
0 ignored issues
show
Bug introduced by
The expression $data of type object<Maniaplanet\Dedic...tructures\Player>|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
506 26
            $key = lcfirst($key);
507 26
            $this->$key = $value;
508
        }
509
510 26
        return $this;
511
    }
512
}
513