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

Player   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 85
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 19 19 1
A createFromArray() 22 22 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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