Player   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 85
ccs 28
cts 28
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 1
A createFromArray() 0 22 1
1
<?php
2
3
namespace PtrTn\Battlerite\Dto\Players;
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 6
    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 6
        $this->type = $type;
60 6
        $this->id = $id;
61 6
        $this->name = $name;
62 6
        $this->patchVersion = $patchVersion;
63 6
        $this->shardId = $shardId;
64 6
        $this->picture = $picture;
65 6
        $this->title = $title;
66 6
        $this->titleId = $titleId;
67 6
    }
68
69 6
    public static function createFromArray(array $player): self
70
    {
71 6
        Assert::string($player['type']);
72 6
        Assert::string($player['id']);
73 6
        Assert::string($player['attributes']['name']);
74 6
        Assert::string($player['attributes']['patchVersion']);
75 6
        Assert::string($player['attributes']['shardId']);
76 6
        Assert::integer($player['attributes']['stats']['picture']);
77 6
        Assert::integer($player['attributes']['stats']['title']);
78 6
        Assert::string($player['attributes']['titleId']);
79
80 6
        return new self(
81 6
            $player['type'],
82 6
            $player['id'],
83 6
            $player['attributes']['name'],
84 6
            $player['attributes']['patchVersion'],
85 6
            $player['attributes']['shardId'],
86 6
            $player['attributes']['stats']['picture'],
87 6
            $player['attributes']['stats']['title'],
88 6
            $player['attributes']['titleId']
89
        );
90
    }
91
}
92