User   A
last analyzed

Complexity

Total Complexity 21

Size/Duplication

Total Lines 188
Duplicated Lines 0 %

Importance

Changes 25
Bugs 0 Features 0
Metric Value
eloc 88
dl 0
loc 188
rs 10
c 25
b 0
f 0
wmc 21

21 Methods

Rating   Name   Duplication   Size   Complexity  
A setOauthHash() 0 4 1
A getUserIdentifier() 0 3 1
A eraseCredentials() 0 2 1
A getUsername() 0 3 1
A setOauthUser() 0 4 1
A getOauthUser() 0 3 1
A setUsername() 0 4 1
A __construct() 0 3 1
A getSalt() 0 3 1
A getPassword() 0 3 1
A setLostPassword() 0 4 1
A getApiKey() 0 3 1
A setHash() 0 4 1
A getHash() 0 3 1
A getOauthHash() 0 3 1
A generateApiKey() 0 4 1
A getPeople() 0 3 1
A setPeople() 0 4 1
A getId() 0 3 1
A getLostPassword() 0 3 1
A getRoles() 0 3 1
1
<?php
2
3
namespace ControleOnline\Entity;
4
5
use Symfony\Component\Serializer\Attribute\Groups;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Serializer\Attribute\Groups 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...
6
7
use ControleOnline\Listener\LogListener;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Listener\LogListener 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 ApiPlatform\Metadata\GetCollection;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\GetCollection 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 ApiPlatform\Metadata\Get;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\Get 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 ApiPlatform\Metadata\ApiResource;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\ApiResource 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 ApiPlatform\Metadata\ApiFilter;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\ApiFilter 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 ApiPlatform\Metadata\Post;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\Post 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
use ApiPlatform\Metadata\Put;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\Put 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 ApiPlatform\Metadata\Delete;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\Delete 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 ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Doctrine\Orm\Filter\SearchFilter 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
use ControleOnline\Controller\ChangeApiKeyAction;
17
use ControleOnline\Controller\ChangePasswordAction;
18
use ControleOnline\Controller\CreateAccountAction;
19
use ControleOnline\Controller\CreateUserAction;
20
use ControleOnline\Controller\SecurityController;
21
use ControleOnline\Entity\People;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\People 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...
22
use ControleOnline\Repository\UserRepository;
23
use Symfony\Component\Security\Core\User\UserInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Security\Core\User\UserInterface 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...
24
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Securi...henticatedUserInterface 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...
25
use Doctrine\ORM\Mapping as ORM;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\Mapping 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...
26
27
#[ORM\Entity(repositoryClass: UserRepository::class)]
28
#[ORM\EntityListeners([LogListener::class])]
29
#[ORM\Table(name: 'users')]
30
#[ORM\UniqueConstraint(name: 'user_name', columns: ['username'])]
31
#[ORM\UniqueConstraint(name: 'api_key', columns: ['api_key'])]
32
#[ORM\Index(name: 'people_id', columns: ['people_id'])]
33
#[ORM\HasLifecycleCallbacks]
34
#[ApiResource(
35
    operations: [
36
        new Post(
37
            uriTemplate: '/users',
38
            controller: CreateUserAction::class,
39
            securityPostDenormalize: 'is_granted(\'ROLE_CLIENT\')',
40
        ),
41
        new Post(
42
            uriTemplate: '/users/create-account',
43
            controller: CreateAccountAction::class,
44
            securityPostDenormalize: 'is_granted(\'PUBLIC_ACCESS\')',
45
        ),
46
        new Delete(security: 'is_granted(\'ROLE_CLIENT\')'),
47
        new Put(
48
            uriTemplate: '/users/{id}/change-api-key',
49
            controller: ChangeApiKeyAction::class,
50
            securityPostDenormalize: 'is_granted(\'ROLE_CLIENT\')',
51
        ),
52
        new Put(
53
            uriTemplate: '/users/{id}/change-password',
54
            controller: ChangePasswordAction::class,
55
            securityPostDenormalize: 'is_granted(\'ROLE_CLIENT\')',
56
        ),
57
        new Post(
58
            uriTemplate: '/token',
59
            controller: SecurityController::class,
60
            securityPostDenormalize: 'is_granted(\'PUBLIC_ACCESS\')',
61
            security: 'is_granted(\'PUBLIC_ACCESS\')',
62
63
        ),
64
        new Get(security: 'is_granted(\'ROLE_CLIENT\')'),
65
        new GetCollection(security: 'is_granted(\'ROLE_CLIENT\')')
66
    ],
67
    formats: ['jsonld', 'json', 'html', 'jsonhal', 'csv' => ['text/csv']],
68
    normalizationContext: ['groups' => ['user:read']],
69
    denormalizationContext: ['groups' => ['user:write']]
70
)]
71
#[ApiFilter(filterClass: SearchFilter::class, properties: ['people' => 'exact'])]
72
class User implements UserInterface, PasswordAuthenticatedUserInterface
73
{
74
    #[ORM\Id]
75
    #[ORM\GeneratedValue(strategy: 'IDENTITY')]
76
    #[ORM\Column(type: 'integer')]
77
    #[Groups(['people:read', 'user:read'])]
78
    private ?int $id = null;
79
80
    #[ORM\Column(type: 'string', length: 50, nullable: false)]
81
    #[Groups(['people:read', 'user:read'])]
82
    private string $username = '';
83
84
    #[ORM\Column(type: 'string', length: 255, nullable: false)]
85
    private string $hash = '';
86
87
    #[ORM\Column(type: 'string', length: 60, nullable: true)]
88
    private ?string $oauthUser = null;
89
90
    #[ORM\Column(type: 'string', length: 60, nullable: true)]
91
    private ?string $oauthHash = null;
92
93
    #[ORM\Column(type: 'string', length: 60, nullable: true)]
94
    private ?string $lostPassword = null;
95
96
    #[ORM\Column(type: 'string', length: 60, nullable: false)]
97
    #[Groups(['people:read', 'user:read'])]
98
    private string $apiKey = '';
99
100
    #[ORM\ManyToOne(targetEntity: People::class, inversedBy: 'user')]
101
    #[ORM\JoinColumn(name: 'people_id', referencedColumnName: 'id', nullable: false)]
102
    #[Groups(['user:read'])]
103
    private People $people;
104
105
    public function __construct()
106
    {
107
        $this->generateApiKey();
108
    }
109
110
    public function getId(): ?int
111
    {
112
        return $this->id;
113
    }
114
115
    public function getUsername(): string
116
    {
117
        return $this->username;
118
    }
119
120
    public function setUsername(string $username): self
121
    {
122
        $this->username = $username;
123
        return $this;
124
    }
125
126
    public function getUserIdentifier(): string
127
    {
128
        return $this->getUsername();
129
    }
130
131
    public function getPassword(): ?string
132
    {
133
        return $this->hash;
134
    }
135
136
    public function getRoles(): array
137
    {
138
        return ['ROLE_CLIENT'];
139
    }
140
141
    public function getSalt(): ?string
142
    {
143
        return null;
144
    }
145
146
    public function eraseCredentials(): void
147
    {
148
        // Clear temporary sensitive data if any
149
    }
150
151
    public function generateApiKey(): string
152
    {
153
        $this->apiKey = md5($this->getUsername() . microtime());
154
        return $this->apiKey;
155
    }
156
157
    public function getApiKey(): string
158
    {
159
        return $this->apiKey;
160
    }
161
162
    public function setHash(string $hash): self
163
    {
164
        $this->hash = $hash;
165
        return $this;
166
    }
167
168
    public function getHash(): string
169
    {
170
        return $this->hash;
171
    }
172
173
    public function getOauthHash(): ?string
174
    {
175
        return $this->oauthHash;
176
    }
177
178
    public function setOauthHash(?string $hash): self
179
    {
180
        $this->oauthHash = $hash;
181
        return $this;
182
    }
183
184
    public function setOauthUser(?string $user): self
185
    {
186
        $this->oauthUser = $user;
187
        return $this;
188
    }
189
190
    public function getOauthUser(): ?string
191
    {
192
        return $this->oauthUser;
193
    }
194
195
    public function setPeople(People $people): self
196
    {
197
        $this->people = $people;
198
        return $this;
199
    }
200
201
    public function getPeople(): People
202
    {
203
        return $this->people;
204
    }
205
206
    public function setLostPassword(?string $hash): self
207
    {
208
        $this->lostPassword = $hash;
209
        return $this;
210
    }
211
212
    public function getLostPassword(): ?string
213
    {
214
        return $this->lostPassword;
215
    }
216
}
217