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

PlayerDto::nickname()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
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