@@ 7-91 (lines=85) @@ | ||
4 | ||
5 | use Webmozart\Assert\Assert; |
|
6 | ||
7 | class DetailedPlayer |
|
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 $name; |
|
23 | ||
24 | /** |
|
25 | * @var string |
|
26 | */ |
|
27 | public $patchVersion; |
|
28 | ||
29 | /** |
|
30 | * @var string |
|
31 | */ |
|
32 | public $shardId; |
|
33 | ||
34 | /** |
|
35 | * @var int |
|
36 | */ |
|
37 | public $picture; |
|
38 | ||
39 | /** |
|
40 | * @var int |
|
41 | */ |
|
42 | public $title; |
|
43 | ||
44 | /** |
|
45 | * @var string |
|
46 | */ |
|
47 | public $titleId; |
|
48 | ||
49 | private function __construct( |
|
50 | string $type, |
|
51 | string $id, |
|
52 | string $name, |
|
53 | string $patchVersion, |
|
54 | string $shardId, |
|
55 | int $picture, |
|
56 | int $title, |
|
57 | string $titleId |
|
58 | ) { |
|
59 | $this->type = $type; |
|
60 | $this->id = $id; |
|
61 | $this->name = $name; |
|
62 | $this->patchVersion = $patchVersion; |
|
63 | $this->shardId = $shardId; |
|
64 | $this->picture = $picture; |
|
65 | $this->title = $title; |
|
66 | $this->titleId = $titleId; |
|
67 | } |
|
68 | ||
69 | public static function createFromArray(array $player): self |
|
70 | { |
|
71 | Assert::string($player['type']); |
|
72 | Assert::string($player['id']); |
|
73 | Assert::string($player['attributes']['name']); |
|
74 | Assert::string($player['attributes']['patchVersion']); |
|
75 | Assert::string($player['attributes']['shardId']); |
|
76 | Assert::integer($player['attributes']['stats']['picture']); |
|
77 | Assert::integer($player['attributes']['stats']['title']); |
|
78 | Assert::string($player['attributes']['titleId']); |
|
79 | ||
80 | return new self( |
|
81 | $player['type'], |
|
82 | $player['id'], |
|
83 | $player['attributes']['name'], |
|
84 | $player['attributes']['patchVersion'], |
|
85 | $player['attributes']['shardId'], |
|
86 | $player['attributes']['stats']['picture'], |
|
87 | $player['attributes']['stats']['title'], |
|
88 | $player['attributes']['titleId'] |
|
89 | ); |
|
90 | } |
|
91 | } |
|
92 |
@@ 7-91 (lines=85) @@ | ||
4 | ||
5 | use Webmozart\Assert\Assert; |
|
6 | ||
7 | class Player |
|
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 $name; |
|
23 | ||
24 | /** |
|
25 | * @var string |
|
26 | */ |
|
27 | public $patchVersion; |
|
28 | ||
29 | /** |
|
30 | * @var string |
|
31 | */ |
|
32 | public $shardId; |
|
33 | ||
34 | /** |
|
35 | * @var int |
|
36 | */ |
|
37 | public $picture; |
|
38 | ||
39 | /** |
|
40 | * @var int |
|
41 | */ |
|
42 | public $title; |
|
43 | ||
44 | /** |
|
45 | * @var string |
|
46 | */ |
|
47 | public $titleId; |
|
48 | ||
49 | private function __construct( |
|
50 | string $type, |
|
51 | string $id, |
|
52 | string $name, |
|
53 | string $patchVersion, |
|
54 | string $shardId, |
|
55 | int $picture, |
|
56 | int $title, |
|
57 | string $titleId |
|
58 | ) { |
|
59 | $this->type = $type; |
|
60 | $this->id = $id; |
|
61 | $this->name = $name; |
|
62 | $this->patchVersion = $patchVersion; |
|
63 | $this->shardId = $shardId; |
|
64 | $this->picture = $picture; |
|
65 | $this->title = $title; |
|
66 | $this->titleId = $titleId; |
|
67 | } |
|
68 | ||
69 | public static function createFromArray(array $player): self |
|
70 | { |
|
71 | Assert::string($player['type']); |
|
72 | Assert::string($player['id']); |
|
73 | Assert::string($player['attributes']['name']); |
|
74 | Assert::string($player['attributes']['patchVersion']); |
|
75 | Assert::string($player['attributes']['shardId']); |
|
76 | Assert::integer($player['attributes']['stats']['picture']); |
|
77 | Assert::integer($player['attributes']['stats']['title']); |
|
78 | Assert::string($player['attributes']['titleId']); |
|
79 | ||
80 | return new self( |
|
81 | $player['type'], |
|
82 | $player['id'], |
|
83 | $player['attributes']['name'], |
|
84 | $player['attributes']['patchVersion'], |
|
85 | $player['attributes']['shardId'], |
|
86 | $player['attributes']['stats']['picture'], |
|
87 | $player['attributes']['stats']['title'], |
|
88 | $player['attributes']['titleId'] |
|
89 | ); |
|
90 | } |
|
91 | } |
|
92 |