Issues (97)

src/Entity/Application.php (2 issues)

1
<?php
2
3
namespace App\Entity;
4
5
use DateTime;
6
use Doctrine\ORM\Mapping as ORM;
7
use Ramsey\Uuid\Uuid;
8
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
9
use Symfony\Component\Security\Core\User\UserInterface;
10
use Symfony\Component\Validator\Constraints as Assert;
11
use Symfony\Component\Validator\Context\ExecutionContextInterface;
12
13
#[ORM\Entity]
14
#[UniqueEntity(fields: ['name'])]
15
class Application implements UserInterface {
16
17
    use IdTrait;
18
    use UuidTrait;
19
20
    #[ORM\Column(type: 'string', length: 64, unique: true)]
21
    #[Assert\Length(max: 64)]
22
    #[Assert\NotBlank]
23
    private string $name;
24
25
    #[ORM\Column(type: 'string', enumType: ApplicationScope::class)]
26
    #[Assert\NotNull]
27
    private ?ApplicationScope $scope = null;
28
29
    #[ORM\ManyToOne(targetEntity: SamlServiceProvider::class)]
30
    #[ORM\JoinColumn(onDelete: 'CASCADE')]
31
    private ?SamlServiceProvider $service = null;
32
33
    #[ORM\Column(type: 'string', length: 64, unique: true)]
34
    private string $apiKey;
35
36
    #[ORM\Column(name: 'description', type: 'text')]
37
    #[Assert\NotBlank]
38
    private string $description;
39
40
    #[ORM\Column(type: 'datetime', nullable: true)]
41
    private $lastActivity;
42
43
    public function __construct() {
44
        $this->uuid = Uuid::uuid4();
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getName() {
51
        return $this->name;
52
    }
53
54
    /**
55
     * @param string $name
56
     */
57
    public function setName($name): Application {
58
        $this->name = $name;
59
        return $this;
60
    }
61 3
62 3
    public function getScope(): ?ApplicationScope {
63 3
        return $this->scope;
64
    }
65
66
    public function setScope(?ApplicationScope $scope): Application {
67
        $this->scope = $scope;
68 1
        return $this;
69 1
    }
70
71
    public function getService(): ?SamlServiceProvider {
72
        return $this->service;
73
    }
74
75
    public function setService(?SamlServiceProvider $service): Application {
76 3
        $this->service = $service;
77 3
        return $this;
78 3
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getApiKey() {
84 1
        return $this->apiKey;
85 1
    }
86
87
    /**
88
     * @param string $apiKey
89
     */
90
    public function setApiKey($apiKey): Application {
91
        $this->apiKey = $apiKey;
92 3
        return $this;
93 3
    }
94 3
95
    /**
96
     * @return string
97
     */
98
    public function getDescription() {
99
        return $this->description;
100
    }
101
102
    /**
103
     * @param string $description
104
     */
105
    public function setDescription($description): Application {
106
        $this->description = $description;
107
        return $this;
108
    }
109
110
    public function getLastActivity(): ?DateTime {
111
        return $this->lastActivity;
112
    }
113
114
    public function setLastActivity(DateTime $lastActivity): Application {
115
        $this->lastActivity = $lastActivity;
116
        return $this;
117
    }
118
119
    public function getRoles(): array {
120
        if($this->scope === ApplicationScope::AdConnect) {
121
            return [ 'ROLE_ADCONNECT' ];
122
        }
123
124 3
        return [
125 3
            'ROLE_API'
126 3
        ];
127
    }
128
129
    /**
130
     * @return string
131
     */
132
    public function getPassword() {
133
        return '';
134
    }
135
136
    /**
137
     * @return null|string
138
     */
139
    public function getSalt() {
140 3
        return null;
141 3
    }
142 3
143
    /**
144
     * @return string
145
     */
146
    public function getUsername() {
147
        return $this->getName();
148
    }
149
150
    public function getUserIdentifier(): string {
151
        return $this->getName();
152
    }
153
154
    /**
155
     * @return mixed
156 3
     */
157 3
    public function eraseCredentials() { }
158 3
159
    #[Assert\Callback]
160
    public function validateService(ExecutionContextInterface $context, $payload) {
0 ignored issues
show
The parameter $payload is not used and could be removed. ( Ignorable by Annotation )

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

160
    public function validateService(ExecutionContextInterface $context, /** @scrutinizer ignore-unused */ $payload) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
161
        if($this->getScope() === ApplicationScope::IdpExchange) {
0 ignored issues
show
The constant App\Entity\ApplicationScope::IdpExchange was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
162
            if($this->getService() === null) {
163
                $context->buildViolation('This value should not be blank.')
164 1
                    ->atPath('service')
165 1
                    ->addViolation();
166
            }
167
        }
168
    }
169
}