User::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
c 1
b 0
f 1
nc 1
nop 4
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace midorikocak\nanoauth;
6
7
use Exception;
8
use midorikocak\arraytools\ArrayConvertableTrait;
9
10
class User implements UserInterface
11
{
12
    use ArrayConvertableTrait;
13
14
    private ?string $id;
15
    private string $username;
16
    private string $email;
17
    private string $password;
18
19 4
    public function __construct(?string $id, string $username, string $email, string $password)
20
    {
21 4
        $this->id = $id;
22 4
        $this->email = $email;
23 4
        $this->username = $username;
24 4
        $this->password = $password;
25 4
    }
26
27 4
    public function getPassword(): string
28
    {
29 4
        return $this->password;
30
    }
31
32 1
    public function getUsername(): string
33
    {
34 1
        return $this->username;
35
    }
36
37 1
    public function getEmail(): string
38
    {
39 1
        return $this->email;
40
    }
41
42 1
    public function getId(): ?string
43
    {
44 1
        return $this->id;
45
    }
46
47
    /**
48
     * @throws Exception
49
     */
50 1
    public function setId(string $id): void
51
    {
52 1
        if ($this->id) {
53
            throw new Exception('Cannot change existing user');
54
        }
55
56 1
        $this->id = $id;
57 1
    }
58
}
59