User   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 94.44%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 17
c 2
b 0
f 1
dl 0
loc 47
ccs 17
cts 18
cp 0.9444
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getUsername() 0 3 1
A getEmail() 0 3 1
A setId() 0 7 2
A getId() 0 3 1
A __construct() 0 6 1
A getPassword() 0 3 1
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