Completed
Push — master ( a3cce1...d6fbcc )
by Marcel
09:39
created

Application   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 197
Duplicated Lines 0 %

Test Coverage

Coverage 54.9%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 42
c 1
b 0
f 0
dl 0
loc 197
ccs 28
cts 51
cp 0.549
rs 10
wmc 23

19 Methods

Rating   Name   Duplication   Size   Complexity  
A getPassword() 0 2 1
A getLastActivity() 0 2 1
A getUsername() 0 2 1
A validateService() 0 6 3
A getApiKey() 0 2 1
A setLastActivity() 0 3 1
A setDescription() 0 3 1
A getDescription() 0 2 1
A eraseCredentials() 0 1 1
A setScope() 0 3 1
A getService() 0 2 1
A setApiKey() 0 3 1
A getScope() 0 2 1
A getRoles() 0 11 3
A getSalt() 0 2 1
A setService() 0 3 1
A setName() 0 3 1
A __construct() 0 2 1
A getName() 0 2 1
1
<?php
2
3
namespace App\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Ramsey\Uuid\Uuid;
7
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
8
use Symfony\Component\Security\Core\User\UserInterface;
9
use Symfony\Component\Validator\Constraints as Assert;
10
use Symfony\Component\Validator\Context\ExecutionContextInterface;
11
12
/**
13
 * @ORM\Entity()
14
 * @UniqueEntity(fields={"name"})
15
 */
16
class Application implements UserInterface {
17
18
    use IdTrait;
19
    use UuidTrait;
20
21
    /**
22
     * @var string
23
     * @ORM\Column(type="string", length=64, unique=true)
24
     * @Assert\Length(max="64")
25
     * @Assert\NotBlank()
26
     */
27
    private $name;
28
29
    /**
30
     * @ORM\Column(type="application_scope")
31
     * @Assert\NotNull()
32
     * @var ApplicationScope
33
     */
34
    private $scope;
35
36
    /**
37
     * @ORM\ManyToOne(targetEntity="ServiceProvider")
38
     * @ORM\JoinColumn(onDelete="CASCADE")
39
     * @var ServiceProvider|null
40
     */
41
    private $service = null;
42
43
    /**
44
     * @var string
45
     * @ORM\Column(type="string", length=64, unique=true)
46
     */
47
    private $apiKey;
48
49
    /**
50
     * @var string
51
     * @ORM\Column(name="`description`", type="text")
52
     * @Assert\NotBlank()
53
     */
54
    private $description;
55
56
    /**
57
     * @ORM\Column(type="datetime", nullable=true)
58
     */
59
    private $lastActivity;
60
61 3
    public function __construct() {
62 3
        $this->uuid = Uuid::uuid4();
63 3
    }
64
65
    /**
66
     * @return string
67
     */
68 1
    public function getName() {
69 1
        return $this->name;
70
    }
71
72
    /**
73
     * @param string $name
74
     * @return Application
75
     */
76 3
    public function setName($name): Application {
77 3
        $this->name = $name;
78 3
        return $this;
79
    }
80
81
    /**
82
     * @return ApplicationScope|null
83
     */
84 1
    public function getScope(): ?ApplicationScope {
85 1
        return $this->scope;
86
    }
87
88
    /**
89
     * @param ApplicationScope|null $scope
90
     * @return Application
91
     */
92 3
    public function setScope(?ApplicationScope $scope): Application {
93 3
        $this->scope = $scope;
94 3
        return $this;
95
    }
96
97
    /**
98
     * @return ServiceProvider|null
99
     */
100
    public function getService(): ?ServiceProvider {
101
        return $this->service;
102
    }
103
104
    /**
105
     * @param ServiceProvider|null $service
106
     * @return Application
107
     */
108
    public function setService(?ServiceProvider $service): Application {
109
        $this->service = $service;
110
        return $this;
111
    }
112
113
    /**
114
     * @return string
115
     */
116
    public function getApiKey() {
117
        return $this->apiKey;
118
    }
119
120
    /**
121
     * @param string $apiKey
122
     * @return Application
123
     */
124 3
    public function setApiKey($apiKey): Application {
125 3
        $this->apiKey = $apiKey;
126 3
        return $this;
127
    }
128
129
    /**
130
     * @return string
131
     */
132
    public function getDescription() {
133
        return $this->description;
134
    }
135
136
    /**
137
     * @param string $description
138
     * @return Application
139
     */
140 3
    public function setDescription($description): Application {
141 3
        $this->description = $description;
142 3
        return $this;
143
    }
144
145
    /**
146
     * @return \DateTime|null
147
     */
148
    public function getLastActivity(): ?\DateTime {
149
        return $this->lastActivity;
150
    }
151
152
    /**
153
     * @param \DateTime $lastActivity
154
     * @return Application
155
     */
156 3
    public function setLastActivity(\DateTime $lastActivity): Application {
157 3
        $this->lastActivity = $lastActivity;
158 3
        return $this;
159
    }
160
161
    /**
162
     * @return mixed
163
     */
164 1
    public function getRoles() {
165 1
        if($this->getScope()->equals(ApplicationScope::IdpExchange())) {
166
            return [ 'ROLE_IDPEXCHANGE' ];
167
        }
168
169 1
        if($this->scope->equals(ApplicationScope::AdConnect())) {
170
            return [ 'ROLE_ADCONNECT' ];
171
        }
172
173
        return [
174 1
            'ROLE_API'
175
        ];
176
    }
177
178
    /**
179
     * @return string
180
     */
181
    public function getPassword() {
182
        return '';
183
    }
184
185
    /**
186
     * @return null|string
187
     */
188
    public function getSalt() {
189
        return null;
190
    }
191
192
    /**
193
     * @return string
194
     */
195 1
    public function getUsername() {
196 1
        return $this->getName();
197
    }
198
199
    /**
200
     * @return mixed
201
     */
202
    public function eraseCredentials() { }
203
204
    /**
205
     * @Assert\Callback()
206
     */
207
    public function validateService(ExecutionContextInterface $context, $payload) {
0 ignored issues
show
Unused Code introduced by
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

207
    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...
208
        if($this->getScope()->equals(ApplicationScope::IdpExchange())) {
209
            if($this->getService() === null) {
210
                $context->buildViolation('This value should not be blank.')
211
                    ->atPath('service')
212
                    ->addViolation();
213
            }
214
        }
215
    }
216
}