Passed
Push — master ( b73665...44e90f )
by Peter
32s
created

Team::createFromArray()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 33
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 37
ccs 33
cts 33
cp 1
rs 8.8571
cc 1
eloc 33
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PtrTn\Battlerite\Dto\Teams;
4
5
use DateTime;
6
use PtrTn\Battlerite\Assert\Assert;
7
8
/**
9
 * @SuppressWarnings(PHPMD.TooManyFields)
10
 */
11
class Team
12
{
13
    /**
14
     * @var string
15
     */
16
    public $type;
17
18
    /**
19
     * @var string
20
     */
21
    public $id;
22
23
    /**
24
     * @var string
25
     */
26
    public $titleId;
27
28
    /**
29
     * @var string
30
     */
31
    public $name;
32
33
    /**
34
     * @var string
35
     */
36
    public $shardId;
37
38
    /**
39
     * @var int
40
     */
41
    public $avatar;
42
43
    /**
44
     * @var int
45
     */
46
    public $division;
47
48
    /**
49
     * @var int
50
     */
51
    public $divisionRating;
52
53
    /**
54
     * @var int
55
     */
56
    public $league;
57
58
    /**
59
     * @var int
60
     */
61
    public $losses;
62
63
    /**
64
     * @var Members
65
     */
66
    public $members;
67
68
    /**
69
     * @var int
70
     */
71
    public $placementGamesLeft;
72
73
    /**
74
     * @var int
75
     */
76
    public $topDivision;
77
78
    /**
79
     * @var int
80
     */
81
    public $topDivisionRating;
82
83
    /**
84
     * @var int
85
     */
86
    public $topLeague;
87
88
    /**
89
     * @var int
90
     */
91
    public $wins;
92
93
    /**
94
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
95
     */
96 2
    private function __construct(
97
        string $type,
98
        string $id,
99
        string $name,
100
        string $shardId,
101
        int $avatar,
102
        int $division,
103
        int $divisionRating,
104
        int $league,
105
        int $losses,
106
        Members $members,
107
        int $placementGamesLeft,
108
        int $topDivision,
109
        int $topDivisionRating,
110
        int $topLeague,
111
        int $wins,
112
        string $titleId
113
    ) {
114 2
        $this->type = $type;
115 2
        $this->id = $id;
116 2
        $this->name = $name;
117 2
        $this->shardId = $shardId;
118 2
        $this->avatar = $avatar;
119 2
        $this->division = $division;
120 2
        $this->divisionRating = $divisionRating;
121 2
        $this->league = $league;
122 2
        $this->losses = $losses;
123 2
        $this->members = $members;
124 2
        $this->placementGamesLeft = $placementGamesLeft;
125 2
        $this->topDivision = $topDivision;
126 2
        $this->topDivisionRating = $topDivisionRating;
127 2
        $this->topLeague = $topLeague;
128 2
        $this->wins = $wins;
129 2
        $this->titleId = $titleId;
130 2
    }
131
132 2
    public static function createFromArray(array $match): self
133
    {
134 2
        Assert::string($match['type']);
135 2
        Assert::string($match['id']);
136 2
        Assert::string($match['attributes']['name']);
137 2
        Assert::string($match['attributes']['shardId']);
138 2
        Assert::integer($match['attributes']['stats']['avatar']);
139 2
        Assert::integer($match['attributes']['stats']['division']);
140 2
        Assert::integer($match['attributes']['stats']['divisionRating']);
141 2
        Assert::integer($match['attributes']['stats']['league']);
142 2
        Assert::integer($match['attributes']['stats']['losses']);
143 2
        Assert::integer($match['attributes']['stats']['placementGamesLeft']);
144 2
        Assert::integer($match['attributes']['stats']['topDivision']);
145 2
        Assert::integer($match['attributes']['stats']['topDivisionRating']);
146 2
        Assert::integer($match['attributes']['stats']['topLeague']);
147 2
        Assert::integer($match['attributes']['stats']['wins']);
148 2
        Assert::string($match['attributes']['titleId']);
149
150 2
        return new self(
151 2
            $match['type'],
152 2
            $match['id'],
153 2
            $match['attributes']['name'],
154 2
            $match['attributes']['shardId'],
155 2
            $match['attributes']['stats']['avatar'],
156 2
            $match['attributes']['stats']['division'],
157 2
            $match['attributes']['stats']['divisionRating'],
158 2
            $match['attributes']['stats']['league'],
159 2
            $match['attributes']['stats']['losses'],
160 2
            Members::createFromArray($match['attributes']['stats']['members']),
161 2
            $match['attributes']['stats']['placementGamesLeft'],
162 2
            $match['attributes']['stats']['topDivision'],
163 2
            $match['attributes']['stats']['topDivisionRating'],
164 2
            $match['attributes']['stats']['topLeague'],
165 2
            $match['attributes']['stats']['wins'],
166 2
            $match['attributes']['titleId']
167
        );
168
    }
169
}
170