Identity   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A regenerateCookieLoginKey() 0 3 1
A validateCookieLoginKey() 0 3 1
A __construct() 0 3 1
A getCookieLoginKey() 0 3 1
A getUser() 0 3 1
A getId() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Auth;
6
7
use App\User\User;
8
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...
9
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...
10
use Cycle\Annotated\Annotation\Relation\BelongsTo;
0 ignored issues
show
Bug introduced by
The type Cycle\Annotated\Annotation\Relation\BelongsTo 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 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...
12
use Yiisoft\User\Login\Cookie\CookieLoginIdentityInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\User\Login\Cooki...eLoginIdentityInterface 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...
13
14
#[Entity(repository: IdentityRepository::class)]
15
class Identity implements CookieLoginIdentityInterface
16
{
17
    #[Column(type: 'primary')]
18
    private ?int $id = null;
0 ignored issues
show
introduced by
The private property $id is not used, and could be removed.
Loading history...
19
20
    #[Column(type: 'string(32)')]
21
    private string $authKey;
22
23
    #[BelongsTo(target: User::class, nullable: false, load: 'eager')]
24
    private ?User $user = null;
25
    private ?int $user_id = null;
0 ignored issues
show
introduced by
The private property $user_id is not used, and could be removed.
Loading history...
26
27
    public function __construct()
28
    {
29
        $this->regenerateCookieLoginKey();
30
    }
31
32
    public function getId(): ?string
33
    {
34
        return $this->user->getId();
0 ignored issues
show
Bug introduced by
The method getId() does not exist on null. ( Ignorable by Annotation )

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

34
        return $this->user->/** @scrutinizer ignore-call */ getId();

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...
35
    }
36
37
    public function getCookieLoginKey(): string
38
    {
39
        return $this->authKey;
40
    }
41
42
    public function getUser(): ?User
43
    {
44
        return $this->user;
45
    }
46
47
    public function validateCookieLoginKey(string $key): bool
48
    {
49
        return $this->authKey === $key;
50
    }
51
52
    public function regenerateCookieLoginKey(): void
53
    {
54
        $this->authKey = Random::string(32);
55
    }
56
}
57