User::getId()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
nc 2
nop 0
cc 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\User;
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();
0 ignored issues
show
Bug introduced by
The method resetToken() does not exist on App\User\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        $this->/** @scrutinizer ignore-call */ 
52
               resetToken();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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;
0 ignored issues
show
Bug Best Practice introduced by
The property token does not exist on App\User\User. Did you maybe forget to declare it?
Loading history...
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