Passed
Pull Request — master (#572)
by Alexander
03:00 queued 01:26
created

User   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 80
rs 10
c 0
b 0
f 0
wmc 11

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setLogin() 0 3 1
A getId() 0 3 2
A __construct() 0 7 1
A validatePassword() 0 3 1
A getToken() 0 3 1
A getCreatedAt() 0 3 1
A getLogin() 0 3 1
A setPassword() 0 3 1
A resetToken() 0 3 1
A getUpdatedAt() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Application\User\Entity;
6
7
use Cycle\Annotated\Annotation\Column;
0 ignored issues
show
Bug introduced by
The type Cycle\Annotated\Annotation\Column was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Cycle\Annotated\Annotation\Entity;
0 ignored issues
show
Bug introduced by
The type Cycle\Annotated\Annotation\Entity was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Cycle\Annotated\Annotation\Table\Index;
0 ignored issues
show
Bug introduced by
The type Cycle\Annotated\Annotation\Table\Index was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Cycle\ORM\Entity\Behavior\CreatedAt;
0 ignored issues
show
Bug introduced by
The type Cycle\ORM\Entity\Behavior\CreatedAt was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Cycle\ORM\Entity\Behavior\UpdatedAt;
0 ignored issues
show
Bug introduced by
The type Cycle\ORM\Entity\Behavior\UpdatedAt was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use DateTimeImmutable;
13
use Yiisoft\Auth\IdentityInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Auth\IdentityInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Yiisoft\Security\PasswordHasher;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Security\PasswordHasher was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Yiisoft\Security\Random;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Security\Random was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
17
#[Entity(repository: UserRepository::class)]
18
#[Index(columns: ['login', 'token'], unique: true)]
19
#[CreatedAt(field: 'created_at', column: 'created_at')]
20
#[UpdatedAt(field: 'updated_at', column: 'updated_at')]
21
class User implements IdentityInterface
22
{
23
    #[Column(type: 'primary')]
24
    private ?int $id = null;
25
26
    #[Column(type: 'string(128)')]
27
    private string $token;
28
29
    #[Column(type: 'string(48)')]
30
    private string $login;
31
32
    #[Column(type: 'string')]
33
    private string $passwordHash;
34
35
    /**
36
     * Annotations for this field placed in a mapper class
37
     */
38
    private DateTimeImmutable $created_at;
39
40
    /**
41
     * Annotations for this field placed in a mapper class
42
     */
43
    private DateTimeImmutable $updated_at;
44
45
    public function __construct(string $login, string $password)
46
    {
47
        $this->login = $login;
48
        $this->created_at = new DateTimeImmutable();
49
        $this->updated_at = new DateTimeImmutable();
50
        $this->setPassword($password);
51
        $this->resetToken();
52
    }
53
54
    public function getId(): ?string
55
    {
56
        return $this->id === null ? null : (string)$this->id;
57
    }
58
59
    public function getToken(): string
60
    {
61
        return $this->token;
62
    }
63
64
    public function resetToken(): void
65
    {
66
        $this->token = Random::string(128);
67
    }
68
69
    public function getLogin(): string
70
    {
71
        return $this->login;
72
    }
73
74
    public function setLogin(string $login): void
75
    {
76
        $this->login = $login;
77
    }
78
79
    public function validatePassword(string $password): bool
80
    {
81
        return (new PasswordHasher())->validate($password, $this->passwordHash);
82
    }
83
84
    public function setPassword(string $password): void
85
    {
86
        $this->passwordHash = (new PasswordHasher())->hash($password);
87
    }
88
89
    public function getCreatedAt(): DateTimeImmutable
90
    {
91
        return $this->created_at;
92
    }
93
94
    public function getUpdatedAt(): DateTimeImmutable
95
    {
96
        return $this->updated_at;
97
    }
98
}
99