Completed
Push — master ( bec978...be88d7 )
by Peter
01:42
created

Player::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 7
crap 1
1
<?php
2
3
namespace PtrTn\Battlerite\Dto;
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 string|null
36
     */
37
    public $stats;
38
39
    /**
40
     * @var string
41
     */
42
    public $titleId;
43
44 3
    private function __construct(
45
        string $type,
46
        string $id,
47
        string $name,
48
        string $patchVersion,
49
        string $shardId,
50
        ?string $stats,
51
        string $titleId
52
    ) {
53 3
        $this->type = $type;
54 3
        $this->id = $id;
55 3
        $this->name = $name;
56 3
        $this->patchVersion = $patchVersion;
57 3
        $this->shardId = $shardId;
58 3
        $this->stats = $stats;
59 3
        $this->titleId = $titleId;
60 3
    }
61
62 3
    public static function createFromArray(array $match): self
63
    {
64 3
        Assert::string($match['type']);
65 3
        Assert::string($match['id']);
66 3
        Assert::string($match['attributes']['name']);
67 3
        Assert::string($match['attributes']['patchVersion']);
68 3
        Assert::string($match['attributes']['shardId']);
69 3
        Assert::nullOrString($match['attributes']['stats']);
70 3
        Assert::string($match['attributes']['titleId']);
71
72 3
        return new self(
73 3
            $match['type'],
74 3
            $match['id'],
75 3
            $match['attributes']['name'],
76 3
            $match['attributes']['patchVersion'],
77 3
            $match['attributes']['shardId'],
78 3
            $match['attributes']['stats'],
79 3
            $match['attributes']['titleId']
80
        );
81
    }
82
}
83