Failed Conditions
Push — issue#767 ( d652de...c7fd2d )
by Guilherme
05:20
created

Organization::getClients()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\OAuthBundle\Entity;
12
13
use Doctrine\ORM\Mapping as ORM;
14
use Doctrine\Common\Collections\ArrayCollection;
15
use LoginCidadao\CoreBundle\Model\PersonInterface;
16
use LoginCidadao\OAuthBundle\Model\ClientInterface;
17
use LoginCidadao\OAuthBundle\Model\OrganizationInterface;
18
use LoginCidadao\OAuthBundle\Validator\Constraints\DomainOwnership;
19
use LoginCidadao\OAuthBundle\Validator\Constraints\SectorIdentifier;
20
use Symfony\Component\Validator\Constraints as Assert;
21
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
22
23
/**
24
 * @ORM\Entity(repositoryClass="LoginCidadao\OAuthBundle\Entity\OrganizationRepository")
25
 * @ORM\Table(name="organization")
26
 * @ORM\HasLifecycleCallbacks()
27
 * @UniqueEntity("domain")
28
 * @UniqueEntity("name")
29
 * @DomainOwnership
30
 * @SectorIdentifier
31
 */
32
class Organization implements OrganizationInterface
33
{
34
    /**
35
     * @ORM\Id
36
     * @ORM\Column(type="integer")
37
     * @ORM\GeneratedValue(strategy="AUTO")
38
     */
39
    protected $id;
40
41
    /**
42
     * @ORM\Column(name="name", type="string", nullable=false, unique=true)
43
     * @Assert\NotBlank
44
     * @var string
45
     */
46
    protected $name;
47
48
    /**
49
     * @var PersonInterface[]
50
     * @ORM\ManyToMany(targetEntity="LoginCidadao\CoreBundle\Model\PersonInterface")
51
     * @ORM\JoinTable(name="person_organizations",
52
     *      joinColumns={@ORM\JoinColumn(name="organization_id", referencedColumnName="id")},
53
     *      inverseJoinColumns={@ORM\JoinColumn(name="person_id", referencedColumnName="id")}
54
     * )
55
     */
56
    protected $members;
57
58
    /**
59
     * @ORM\Column(name="verified_at", type="datetime", nullable=true)
60
     * @var \DateTime
61
     */
62
    protected $verifiedAt;
63
64
    /**
65
     * @ORM\Column(name="domain", type="string", nullable=false, unique=true)
66
     * @var string
67
     */
68
    protected $domain;
69
70
    /**
71
     * @ORM\OneToMany(targetEntity="LoginCidadao\OpenIDBundle\Entity\ClientMetadata", mappedBy="organization")
72
     * @var ClientInterface
73
     */
74
    protected $clients;
75
76
    /**
77
     * @Assert\Url
78
     * @ORM\Column(name="validation_url", type="string", nullable=true, unique=true)
79
     * @var string
80
     */
81
    protected $validationUrl;
82
83
    /**
84
     * @ORM\Column(name="validation_secret", type="string", nullable=true)
85
     * @var string
86
     */
87
    protected $validationSecret;
88
89
    /**
90
     * @ORM\Column(name="validated_url", type="string", nullable=true)
91
     * @var string
92
     */
93
    protected $validatedUrl;
94
95
    /**
96
     * @ORM\Column(name="trusted", type="boolean", nullable=false)
97
     * @var boolean
98
     */
99
    protected $trusted;
100
101
    /**
102
     * @Assert\Url
103
     * @ORM\Column(name="sector_identifier_uri", type="string", nullable=true, unique=true)
104
     * @var string
105
     */
106
    protected $sectorIdentifierUri;
107
108 2
    public function __construct()
109
    {
110 2
        $this->members = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Doctrine\Common\Collections\ArrayCollection() of type Doctrine\Common\Collections\ArrayCollection is incompatible with the declared type LoginCidadao\CoreBundle\Model\PersonInterface[] of property $members.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
111 2
        $this->clients = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Doctrine\Common\Collections\ArrayCollection() of type Doctrine\Common\Collections\ArrayCollection is incompatible with the declared type LoginCidadao\OAuthBundle\Model\ClientInterface of property $clients.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
112 2
        $this->initializeValidationCode();
113 2
        $this->trusted = false;
114 2
    }
115
116
    public function getId()
117
    {
118
        return $this->id;
119
    }
120
121
    public function setId($id)
122
    {
123
        $this->id = $id;
124
125
        return $this;
126
    }
127
128
    public function getName()
129
    {
130
        return $this->name;
131
    }
132
133
    public function setName($name)
134
    {
135
        $this->name = $name;
136
137
        return $this;
138
    }
139
140
    /**
141
     * @return PersonInterface[]
142
     */
143
    public function getMembers()
144
    {
145
        return $this->members;
146
    }
147
148
    /**
149
     * @param PersonInterface[] $members
150
     * @return \Organization
0 ignored issues
show
Bug introduced by
The type Organization 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...
151
     */
152
    public function setMembers(array $members)
153
    {
154
        $this->members = $members;
155
156
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type LoginCidadao\OAuthBundle\Entity\Organization which is incompatible with the documented return type Organization.
Loading history...
157
    }
158
159
    /**
160
     * @return \DateTime
161
     */
162
    public function getVerifiedAt()
163
    {
164
        return $this->verifiedAt;
165
    }
166
167
    /**
168
     * @param \DateTime $verifiedAt
169
     * @return \Organization
170
     */
171
    public function setVerifiedAt($verifiedAt)
172
    {
173
        $this->verifiedAt = $verifiedAt;
174
175
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type LoginCidadao\OAuthBundle\Entity\Organization which is incompatible with the documented return type Organization.
Loading history...
176
    }
177
178
    public function getDomain()
179
    {
180
        return $this->domain;
181
    }
182
183
    public function setDomain($domain)
184
    {
185
        $this->domain = $domain;
186
187
        return $this;
188
    }
189
190
    public function getClients()
191
    {
192
        return $this->clients;
193
    }
194
195
    public function setClients(array $clients)
196
    {
197
        $this->clients = $clients;
0 ignored issues
show
Documentation Bug introduced by
It seems like $clients of type array is incompatible with the declared type LoginCidadao\OAuthBundle\Model\ClientInterface of property $clients.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
198
199
        return $this;
200
    }
201
202
    public function getValidationUrl()
203
    {
204
        return $this->validationUrl;
205
    }
206
207
    public function setValidationUrl($validationUrl)
208
    {
209
        $this->validationUrl = $validationUrl;
210
211
        return $this;
212
    }
213
214
    public function getValidationSecret()
215
    {
216
        $this->initializeValidationCode();
217
218
        return $this->validationSecret;
219
    }
220
221 2
    public function setValidationSecret($validationSecret)
222
    {
223 2
        $this->validationSecret = $validationSecret;
224
225 2
        return $this;
226
    }
227
228
    public function checkValidation()
229
    {
230
        if ($this->validatedUrl !== $this->getValidationUrl()) {
231
            $this->setVerifiedAt(null);
232
            $this->validatedUrl = null;
233
234
            return false;
235
        }
236
237
        return true;
238
    }
239
240
    public function setValidatedUrl($validatedUrl)
241
    {
242
        $this->validatedUrl = $validatedUrl;
243
244
        return $this;
245
    }
246
247
    public function __toString()
248
    {
249
        return $this->getName();
250
    }
251
252
    public function isVerified()
253
    {
254
        return $this->getVerifiedAt() instanceof \DateTime;
255
    }
256
257
    public function isTrusted()
258
    {
259
        return $this->trusted;
260
    }
261
262
    /**
263
     *
264
     * @param boolean $trusted
265
     * @return \LoginCidadao\OAuthBundle\Entity\Organization
266
     */
267
    public function setTrusted($trusted)
268
    {
269
        $this->trusted = $trusted;
270
271
        return $this;
272
    }
273
274
    /**
275
     * @return string
276
     */
277
    public function getSectorIdentifierUri()
278
    {
279
        return $this->sectorIdentifierUri;
280
    }
281
282
    /**
283
     * @param string $sectorIdentifierUri
284
     */
285
    public function setSectorIdentifierUri($sectorIdentifierUri)
286
    {
287
        $this->sectorIdentifierUri = $sectorIdentifierUri;
288
    }
289
290
    /**
291
     * @ORM\PrePersist
292
     * @ORM\PreUpdate
293
     */
294 2
    private function initializeValidationCode()
295
    {
296 2
        if ($this->validationSecret) {
297
            return;
298
        }
299 2
        $random = base64_encode(random_bytes(35));
300 2
        $this->setValidationSecret($random);
301 2
    }
302
303
304
}
305