Roster   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 69
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A createFromArray() 0 20 2
1
<?php
2
3
namespace PtrTn\Battlerite\Dto\Match;
4
5
use Webmozart\Assert\Assert;
6
7
class Roster
8
{
9
    /**
10
     * @var string
11
     */
12
    public $type;
13
14
    /**
15
     * @var string
16
     */
17
    public $id;
18
19
    /**
20
     * @var string
21
     */
22
    public $shardId;
23
24
    /**
25
     * @var int
26
     */
27
    public $score;
28
29
    /**
30
     * @var bool
31
     */
32
    public $won;
33
34
    /**
35
     * @var References
36
     */
37
    public $participants;
38
39 12
    private function __construct(
40
        string $type,
41
        string $id,
42
        string $shardId,
43
        int $score,
44
        bool $won,
45
        References $participants
46
    ) {
47 12
        $this->type = $type;
48 12
        $this->id = $id;
49 12
        $this->shardId = $shardId;
50 12
        $this->score = $score;
51 12
        $this->won = $won;
52 12
        $this->participants = $participants;
53 12
    }
54
55 12
    public static function createFromArray(array $roster): self
56
    {
57 12
        Assert::string($roster['type']);
58 12
        Assert::string($roster['id']);
59 12
        Assert::string($roster['attributes']['shardId']);
60 12
        Assert::integer($roster['attributes']['stats']['score']);
61 12
        Assert::string($roster['attributes']['won']);
62
63
        // Todo, this should probably be a boolean in json.
64 12
        $won = $roster['attributes']['won'] ?: filter_var($roster['attributes']['won'], FILTER_VALIDATE_BOOLEAN);
65
66 12
        return new self(
67 12
            $roster['type'],
68 12
            $roster['id'],
69 12
            $roster['attributes']['shardId'] ?? null,
70 12
            $roster['attributes']['stats']['score'] ?? null,
71 12
            $won,
72 12
            References::createFromArray($roster['relationships']['participants']['data'])
73
        );
74
    }
75
}
76