Passed
Push — master ( 6efd44...835b8c )
by Luiz Kim
14:33 queued 12:23
created

User::getUserIdentifier()   A

Complexity

Conditions 1
Paths 1

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
cc 1
nc 1
nop 0
1
<?php
2
3
namespace ControleOnline\Entity;
4
5
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...
6
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...
7
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...
8
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...
9
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...
10
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...
11
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...
12
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...
13
use ControleOnline\Controller\ChangeApiKeyAction;
14
use ControleOnline\Controller\ChangePasswordAction;
15
use ControleOnline\Controller\CreateAccountAction;
16
use ControleOnline\Controller\CreateUserAction;
17
use ControleOnline\Controller\Oauth\MercadolivreReturnController;
18
use ControleOnline\Controller\SecurityController;
19
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...
20
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...
21
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...
22
use Symfony\Component\Serializer\Annotation\Groups;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Serializer\Annotation\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...
23
24
#[ORM\Entity(repositoryClass: 'ControleOnline\Repository\UserRepository')]
25
#[ORM\EntityListeners(['ControleOnline\Listener\LogListener'])]
26
#[ORM\Table(name: 'users')]
27
#[ORM\UniqueConstraint(name: 'user_name', columns: ['username'])]
28
#[ORM\UniqueConstraint(name: 'api_key', columns: ['api_key'])]
29
#[ORM\Index(name: 'people_id', columns: ['people_id'])]
30
#[ORM\HasLifecycleCallbacks]
31
#[ApiResource(
32
    operations: [
33
        new GetCollection(
34
            security: 'is_granted(\'IS_AUTHENTICATED_ANONYMOUSLY\')',
35
            uriTemplate: '/oauth/mercadolivre/return',
36
            controller: MercadolivreReturnController::class,
37
        ),
38
        new Post(
39
            uriTemplate: '/users',
40
            controller: CreateUserAction::class,
41
            securityPostDenormalize: 'is_granted(\'ROLE_CLIENT\')',
42
        ),
43
        new Post(
44
            uriTemplate: '/users/create-account',
45
            controller: CreateAccountAction::class,
46
            securityPostDenormalize: 'is_granted(\'IS_AUTHENTICATED_ANONYMOUSLY\')',
47
        ),
48
        new Delete(security: 'is_granted(\'ROLE_CLIENT\')'),
49
        new Put(
50
            uriTemplate: '/users/{id}/change-api-key',
51
            controller: ChangeApiKeyAction::class,
52
            securityPostDenormalize: 'is_granted(\'ROLE_CLIENT\')',
53
        ),
54
        new Put(
55
            uriTemplate: '/users/{id}/change-password',
56
            controller: ChangePasswordAction::class,
57
            securityPostDenormalize: 'is_granted(\'ROLE_CLIENT\')',
58
        ),
59
        new Post(
60
            uriTemplate: '/token',
61
            controller: SecurityController::class,
62
            securityPostDenormalize: 'is_granted(\'IS_AUTHENTICATED_ANONYMOUSLY\')',
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
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(['people:read', '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 (string) $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
}