1 | <?php |
||
12 | class User extends BaseUser implements VictoireUserInterface |
||
13 | { |
||
14 | use \Gedmo\Timestampable\Traits\TimestampableEntity; |
||
15 | |||
16 | /** |
||
17 | * @ORM\Id |
||
18 | * @ORM\Column(type="integer") |
||
19 | * @ORM\GeneratedValue(strategy="AUTO") |
||
20 | */ |
||
21 | protected $id; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | * |
||
26 | * @ORM\Column(name="firstname", type="string", length=255, nullable=true) |
||
27 | * @Groups({"profile"}) |
||
28 | */ |
||
29 | protected $firstname; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | * |
||
34 | * @ORM\Column(name="lastname", type="string", length=255, nullable=true) |
||
35 | * @Groups({"profile"}) |
||
36 | */ |
||
37 | protected $lastname; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | * |
||
42 | * @ORM\Column(name="locale", type="string", length=255, nullable=true) |
||
43 | * @Groups({"profile"}) |
||
44 | */ |
||
45 | protected $locale; |
||
46 | |||
47 | /** |
||
48 | * @var \DateTime |
||
49 | * |
||
50 | * @ORM\Column(name="heartbeat", type="datetime", nullable=true) |
||
51 | */ |
||
52 | protected $heartbeat; |
||
53 | |||
54 | protected $pages; |
||
55 | protected $articles; |
||
56 | |||
57 | /** |
||
58 | * Get firstname. |
||
59 | * |
||
60 | * @return string |
||
61 | */ |
||
62 | public function getFirstname() |
||
66 | |||
67 | /** |
||
68 | * Set firstname. |
||
69 | * |
||
70 | * @param string $firstname |
||
71 | * |
||
72 | * @return $this |
||
73 | */ |
||
74 | public function setFirstname($firstname) |
||
80 | |||
81 | /** |
||
82 | * Get lastname. |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | public function getLastname() |
||
90 | |||
91 | /** |
||
92 | * Set lastname. |
||
93 | * |
||
94 | * @param string $lastname |
||
95 | * |
||
96 | * @return $this |
||
97 | */ |
||
98 | public function setLastname($lastname) |
||
104 | |||
105 | /** |
||
106 | * Get fullName. |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | public function getFullName() |
||
114 | |||
115 | /** |
||
116 | * Get locale. |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | public function getLocale() |
||
124 | |||
125 | /** |
||
126 | * Set locale. |
||
127 | * |
||
128 | * @param string $locale |
||
129 | * |
||
130 | * @return $this |
||
131 | */ |
||
132 | public function setLocale($locale) |
||
138 | |||
139 | /** |
||
140 | * @return \DateTime |
||
141 | */ |
||
142 | public function getHeartbeat() |
||
146 | |||
147 | /** |
||
148 | * @param \DateTime $heartbeat |
||
149 | */ |
||
150 | public function setHeartbeat($heartbeat) |
||
154 | } |
||
155 |
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.