|
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\OpenIDBundle\Entity; |
|
12
|
|
|
|
|
13
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
14
|
|
|
use LoginCidadao\CoreBundle\Model\PersonInterface; |
|
15
|
|
|
use LoginCidadao\OAuthBundle\Model\ClientInterface; |
|
16
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @ORM\Entity(repositoryClass="LoginCidadao\OpenIDBundle\Entity\SubjectIdentifierRepository") |
|
20
|
|
|
* @UniqueEntity({"client", "person"}) |
|
21
|
|
|
* @ORM\HasLifecycleCallbacks |
|
22
|
|
|
* @ORM\Table(name="subject_identifier") |
|
23
|
|
|
*/ |
|
24
|
|
|
class SubjectIdentifier |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @ORM\Id |
|
28
|
|
|
* @ORM\Column(type="integer") |
|
29
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $id; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var PersonInterface |
|
35
|
|
|
* @ORM\ManyToOne(targetEntity="LoginCidadao\CoreBundle\Entity\Person") |
|
36
|
|
|
* @ORM\JoinColumn(name="person_id", referencedColumnName="id", nullable=false) |
|
37
|
|
|
*/ |
|
38
|
|
|
private $person; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var ClientInterface |
|
42
|
|
|
* @ORM\ManyToOne(targetEntity="LoginCidadao\OAuthBundle\Entity\Client", inversedBy="authorizations") |
|
43
|
|
|
* @ORM\JoinColumn(name="client_id", referencedColumnName="id", nullable=false) |
|
44
|
|
|
*/ |
|
45
|
|
|
private $client; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var mixed |
|
49
|
|
|
* @ORM\Column(name="subject_identifier", type="string", nullable=false) |
|
50
|
|
|
*/ |
|
51
|
|
|
private $subjectIdentifier; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var \DateTime |
|
55
|
|
|
* @ORM\Column(name="created_at", type="datetime") |
|
56
|
|
|
*/ |
|
57
|
|
|
private $createdAt; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var \DateTime |
|
61
|
|
|
* @ORM\Column(name="updated_at", type="datetime") |
|
62
|
|
|
*/ |
|
63
|
|
|
private $updatedAt; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return mixed |
|
67
|
|
|
*/ |
|
68
|
1 |
|
public function getPerson() |
|
69
|
|
|
{ |
|
70
|
1 |
|
return $this->person; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param mixed $person |
|
75
|
|
|
* @return SubjectIdentifier |
|
76
|
|
|
*/ |
|
77
|
3 |
|
public function setPerson(PersonInterface $person) |
|
78
|
|
|
{ |
|
79
|
3 |
|
$this->person = $person; |
|
80
|
|
|
|
|
81
|
3 |
|
return $this; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @return ClientInterface |
|
86
|
|
|
*/ |
|
87
|
1 |
|
public function getClient() |
|
88
|
|
|
{ |
|
89
|
1 |
|
return $this->client; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param ClientInterface $client |
|
94
|
|
|
* @return SubjectIdentifier |
|
95
|
|
|
*/ |
|
96
|
3 |
|
public function setClient(ClientInterface $client) |
|
97
|
|
|
{ |
|
98
|
3 |
|
$this->client = $client; |
|
99
|
|
|
|
|
100
|
3 |
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return mixed |
|
105
|
|
|
*/ |
|
106
|
1 |
|
public function getSubjectIdentifier() |
|
107
|
|
|
{ |
|
108
|
1 |
|
return $this->subjectIdentifier; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param mixed $subjectIdentifier |
|
113
|
|
|
* @return SubjectIdentifier |
|
114
|
|
|
*/ |
|
115
|
3 |
|
public function setSubjectIdentifier($subjectIdentifier) |
|
116
|
|
|
{ |
|
117
|
3 |
|
$this->subjectIdentifier = $subjectIdentifier; |
|
118
|
|
|
|
|
119
|
3 |
|
return $this; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @return mixed |
|
124
|
|
|
*/ |
|
125
|
2 |
|
public function getCreatedAt() |
|
126
|
|
|
{ |
|
127
|
2 |
|
return $this->createdAt; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @ORM\PrePersist() |
|
132
|
|
|
* @param mixed $createdAt |
|
133
|
|
|
* @return SubjectIdentifier |
|
134
|
|
|
*/ |
|
135
|
2 |
|
public function setCreatedAt($createdAt = null) |
|
136
|
|
|
{ |
|
137
|
2 |
|
if ($createdAt instanceof \DateTime) { |
|
138
|
1 |
|
$this->createdAt = $createdAt; |
|
139
|
|
|
} else { |
|
140
|
1 |
|
$this->createdAt = \DateTime::createFromFormat('U', time()); |
|
|
|
|
|
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
2 |
|
return $this; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @return \DateTime |
|
148
|
|
|
*/ |
|
149
|
2 |
|
public function getUpdatedAt() |
|
150
|
|
|
{ |
|
151
|
2 |
|
return $this->updatedAt; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @ORM\PrePersist() |
|
156
|
|
|
* @ORM\PreUpdate() |
|
157
|
|
|
* @param \DateTime $updatedAt |
|
158
|
|
|
* @return SubjectIdentifier |
|
159
|
|
|
*/ |
|
160
|
2 |
|
public function setUpdatedAt($updatedAt = null) |
|
161
|
|
|
{ |
|
162
|
2 |
|
if ($updatedAt instanceof \DateTime) { |
|
163
|
1 |
|
$this->updatedAt = $updatedAt; |
|
164
|
|
|
} else { |
|
165
|
1 |
|
$this->updatedAt = \DateTime::createFromFormat('U', time()); |
|
|
|
|
|
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
2 |
|
return $this; |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.