PlayerDto::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 6
ccs 0
cts 5
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\Registration\Player;
6
7
use App\Game\Features\Registration\Role\Role;
8
use JsonSerializable;
9
10
/**
11
 * @psalm-immutable
12
 */
13
final class PlayerDto implements JsonSerializable
14
{
15
    private Role $role;
16
    private PlayerId $playerId;
17
    private string $password;
18
    private string $nickname;
19
20
    public function __construct(PlayerId $playerId, string $password, string $nickname, Role $role)
21
    {
22
        $this->playerId = $playerId;
23
        $this->role = $role;
24
        $this->nickname = $nickname;
25
        $this->password = $password;
26
    }
27
28
    public function playerId(): PlayerId
29
    {
30
        return $this->playerId;
31
    }
32
33
    public function role(): Role
34
    {
35
        return $this->role;
36
    }
37
38
    public function nickname(): string
39
    {
40
        return $this->nickname;
41
    }
42
43
    public function password(): string
44
    {
45
        return $this->password;
46
    }
47
48
    public function jsonSerialize(): array
49
    {
50
        return [
51
            'id' => (string) $this->playerId,
52
            'nickname' => $this->nickname,
53
            'password' => $this->password,
54
            'level' => 1,
55
            'role' => (string) $this->role->getValue(),
56
        ];
57
    }
58
}
59