1 | <?php |
||
20 | abstract class User implements UserInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var int |
||
24 | * |
||
25 | * @ORM\Id |
||
26 | * @ORM\GeneratedValue |
||
27 | * @ORM\Column(name="id", type="integer") |
||
28 | */ |
||
29 | protected $id; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | * |
||
34 | * @ORM\Column(name="username", type="string", length=30, unique=true) |
||
35 | */ |
||
36 | protected $username; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | * |
||
41 | * @ORM\Column(name="email", type="string", length=255, unique=true) |
||
42 | */ |
||
43 | protected $email; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | * |
||
48 | * @ORM\Column(name="password", type="string", length=255) |
||
49 | */ |
||
50 | protected $password; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $plainPassword; |
||
56 | |||
57 | /** |
||
58 | * @var string |
||
59 | * |
||
60 | * @ORM\Column(name="salt", type="string", nullable=true) |
||
61 | */ |
||
62 | protected $salt; |
||
63 | |||
64 | /** |
||
65 | * @var bool |
||
66 | * |
||
67 | * @ORM\Column(name="enabled", type="boolean") |
||
68 | */ |
||
69 | protected $enabled = false; |
||
70 | |||
71 | /** |
||
72 | * @var array |
||
73 | * |
||
74 | * @ORM\Column(name="roles", type="array") |
||
75 | */ |
||
76 | protected $roles = []; |
||
77 | |||
78 | /** |
||
79 | * @var string |
||
80 | * |
||
81 | * @ORM\Column(name="confirmation_token", type="string", unique=true, nullable=true) |
||
82 | */ |
||
83 | protected $confirmationToken; |
||
84 | |||
85 | public static function loadValidatorMetadata(ClassMetadata $metadata) |
||
123 | |||
124 | /** |
||
125 | * {@inheritdoc} |
||
126 | */ |
||
127 | public function isAccountNonExpired() |
||
131 | |||
132 | /** |
||
133 | * {@inheritdoc} |
||
134 | */ |
||
135 | public function isAccountNonLocked() |
||
139 | |||
140 | /** |
||
141 | * {@inheritdoc} |
||
142 | */ |
||
143 | public function isCredentialsNonExpired() |
||
147 | |||
148 | /** |
||
149 | * {@inheritdoc} |
||
150 | */ |
||
151 | public function eraseCredentials() |
||
155 | |||
156 | /** |
||
157 | * {@inheritdoc} |
||
158 | */ |
||
159 | public function isEnabled() |
||
163 | |||
164 | /** |
||
165 | * {@inheritdoc} |
||
166 | */ |
||
167 | public function setEnabled($enabled) |
||
173 | |||
174 | /** |
||
175 | * {@inheritdoc} |
||
176 | */ |
||
177 | public function getId() |
||
181 | |||
182 | /** |
||
183 | * {@inheritdoc} |
||
184 | */ |
||
185 | public function setUsername($username) |
||
191 | |||
192 | /** |
||
193 | * {@inheritdoc} |
||
194 | */ |
||
195 | public function getUsername() |
||
199 | |||
200 | /** |
||
201 | * {@inheritdoc} |
||
202 | */ |
||
203 | public function setEmail($email) |
||
209 | |||
210 | /** |
||
211 | * {@inheritdoc} |
||
212 | */ |
||
213 | public function getEmail() |
||
217 | |||
218 | /** |
||
219 | * {@inheritdoc} |
||
220 | */ |
||
221 | public function setPassword($password) |
||
227 | |||
228 | /** |
||
229 | * {@inheritdoc} |
||
230 | */ |
||
231 | public function getPassword() |
||
235 | |||
236 | /** |
||
237 | * {@inheritdoc} |
||
238 | */ |
||
239 | public function setPlainPassword($password) |
||
245 | |||
246 | /** |
||
247 | * {@inheritdoc} |
||
248 | */ |
||
249 | public function getPlainPassword() |
||
253 | |||
254 | /** |
||
255 | * {@inheritdoc} |
||
256 | */ |
||
257 | public function setSalt($salt) |
||
263 | |||
264 | /** |
||
265 | * {@inheritdoc} |
||
266 | */ |
||
267 | public function getSalt() |
||
271 | |||
272 | /** |
||
273 | * {@inheritdoc} |
||
274 | */ |
||
275 | public function setRoles(array $roles) |
||
281 | |||
282 | /** |
||
283 | * {@inheritdoc} |
||
284 | */ |
||
285 | public function getRoles() |
||
293 | |||
294 | /** |
||
295 | * {@inheritdoc} |
||
296 | */ |
||
297 | public function hasRole($role) |
||
301 | |||
302 | /** |
||
303 | * {@inheritdoc} |
||
304 | */ |
||
305 | public function addRole($role) |
||
318 | |||
319 | /** |
||
320 | * {@inheritdoc} |
||
321 | */ |
||
322 | public function removeRole($role) |
||
332 | |||
333 | /** |
||
334 | * {@inheritdoc} |
||
335 | */ |
||
336 | public function setConfirmationToken($token) |
||
342 | |||
343 | /** |
||
344 | * {@inheritdoc} |
||
345 | */ |
||
346 | public function getConfirmationToken() |
||
350 | } |
||
351 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.