Player::playerId()   A
last analyzed

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 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 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Game\Features\Player\Player;
6
7
use App\Game\Features\Player\AggregateRoot;
8
use App\Game\Features\Player\Level\Level;
9
use App\Game\Features\Player\Level\LevelUpEvent;
10
use DateTimeImmutable;
11
12
class Player extends AggregateRoot
13
{
14
    private PlayerId $playerId;
15
    private DateTimeImmutable $createdAt;
16
    private DateTimeImmutable $updatedAt;
17
    private string $password;
18
    private string $nickname;
19
    private string $role;
20
    private int $level;
21
22
    public function __construct(PlayerId $playerId)
23
    {
24
        $this->playerId = $playerId;
25
        $this->createdAt = new DateTimeImmutable();
26
        $this->updatedAt = new DateTimeImmutable();
27
    }
28
29
    public function changeRole(Role $role): void
30
    {
31
        $this->role = (string) $role->getValue();
32
    }
33
34
    public function changeNickname(string $nickname): void
35
    {
36
        $this->nickname = $nickname;
37
    }
38
39
    public function changePassword(string $password): void
40
    {
41
        $this->password = $password;
42
    }
43
44 2
    public function changeLevel(int $level): void
45
    {
46 2
        $this->level = $level;
47
48 2
        $this->updatedAt = new DateTimeImmutable();
49
50 2
        if (Level::LAST_LEVEL > $this->level) {
51 2
            $this->raise(new LevelUpEvent($this->playerId, $level));
52
        }
53 2
    }
54
55
    public function playerId(): PlayerId
56
    {
57
        return $this->playerId;
58
    }
59
60
    public function level(): int
61
    {
62
        return $this->level;
63
    }
64
65
    public function role(): Role
66
    {
67
        return new Role($this->role);
68
    }
69
70
    public function password(): string
71
    {
72
        return $this->password;
73
    }
74
75
    public function nickname(): string
76
    {
77
        return $this->nickname;
78
    }
79
}
80