Passed
Push — master ( bdc105...ec8122 )
by Peter
01:57
created

DetailedPlayer::createFromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 18

Duplication

Lines 22
Ratio 100 %

Code Coverage

Tests 18
CRAP Score 1

Importance

Changes 0
Metric Value
dl 22
loc 22
ccs 18
cts 18
cp 1
rs 9.2
c 0
b 0
f 0
cc 1
eloc 18
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PtrTn\Battlerite\Dto\Player;
4
5
use Webmozart\Assert\Assert;
6
7 View Code Duplication
class DetailedPlayer
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 1
    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 1
        $this->type = $type;
60 1
        $this->id = $id;
61 1
        $this->name = $name;
62 1
        $this->patchVersion = $patchVersion;
63 1
        $this->shardId = $shardId;
64 1
        $this->picture = $picture;
65 1
        $this->title = $title;
66 1
        $this->titleId = $titleId;
67 1
    }
68
69 1
    public static function createFromArray(array $player): self
70
    {
71 1
        Assert::string($player['type']);
72 1
        Assert::string($player['id']);
73 1
        Assert::string($player['attributes']['name']);
74 1
        Assert::string($player['attributes']['patchVersion']);
75 1
        Assert::string($player['attributes']['shardId']);
76 1
        Assert::integer($player['attributes']['stats']['picture']);
77 1
        Assert::integer($player['attributes']['stats']['title']);
78 1
        Assert::string($player['attributes']['titleId']);
79
80 1
        return new self(
81 1
            $player['type'],
82 1
            $player['id'],
83 1
            $player['attributes']['name'],
84 1
            $player['attributes']['patchVersion'],
85 1
            $player['attributes']['shardId'],
86 1
            $player['attributes']['stats']['picture'],
87 1
            $player['attributes']['stats']['title'],
88 1
            $player['attributes']['titleId']
89
        );
90
    }
91
}
92