Passed
Push — master ( 35eebd...7b8a1a )
by Roman
16:45
created

PlayerDto   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 42
ccs 0
cts 19
cp 0
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A level() 0 3 1
A role() 0 3 1
A nickname() 0 3 1
A playerId() 0 3 1
A __construct() 0 6 1
A jsonSerialize() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Game\Features\Player\Player;
6
7
use JsonSerializable;
8
9
/**
10
 * @psalm-immutable
11
 */
12
final class PlayerDto implements JsonSerializable
13
{
14
    private Role $role;
15
    private PlayerId $playerId;
16
    private int $level;
17
    private string $nickname;
18
19
    public function __construct(PlayerId $playerId, string $nickname, int $level, Role $role)
20
    {
21
        $this->playerId = $playerId;
22
        $this->role = $role;
23
        $this->level = $level;
24
        $this->nickname = $nickname;
25
    }
26
27
    public function playerId(): PlayerId
28
    {
29
        return $this->playerId;
30
    }
31
32
    public function level(): int
33
    {
34
        return $this->level;
35
    }
36
37
    public function role(): Role
38
    {
39
        return $this->role;
40
    }
41
42
    public function nickname(): string
43
    {
44
        return $this->nickname;
45
    }
46
47
    public function jsonSerialize(): array
48
    {
49
        return [
50
            'id' => (string) $this->playerId,
51
            'nickname' => $this->nickname,
52
            'level' => $this->level,
53
            'role' => (string) $this->role->getValue(),
54
        ];
55
    }
56
}
57