1 | <?php |
||
19 | class Story |
||
20 | { |
||
21 | |||
22 | 1 | public static function fromList(EntityManager $entityManager, array $values) |
|
32 | |||
33 | 2 | public static function fromValue(EntityManager $entityManager, \stdClass $value) |
|
37 | |||
38 | /** |
||
39 | * @var EntityManager |
||
40 | */ |
||
41 | protected $entityManager; |
||
42 | |||
43 | /** |
||
44 | * @var \stdClass |
||
45 | */ |
||
46 | protected $source; |
||
47 | |||
48 | /** |
||
49 | * @var \DateTime |
||
50 | */ |
||
51 | protected $updatedOn; |
||
52 | |||
53 | /** |
||
54 | * @var \DateTime |
||
55 | */ |
||
56 | protected $createdOn; |
||
57 | |||
58 | /** |
||
59 | * @var Subdef|null |
||
60 | */ |
||
61 | protected $thumbnail; |
||
62 | |||
63 | /** |
||
64 | * @var ArrayCollection|Record[] |
||
65 | */ |
||
66 | protected $records; |
||
67 | |||
68 | /** |
||
69 | * @var ArrayCollection|Metadata[] |
||
70 | */ |
||
71 | protected $metadata; |
||
72 | |||
73 | /** |
||
74 | * @var ArrayCollection|RecordStatus[] |
||
75 | */ |
||
76 | protected $status; |
||
77 | |||
78 | /** |
||
79 | * @var ArrayCollection|RecordCaption[] |
||
80 | */ |
||
81 | protected $caption; |
||
82 | |||
83 | /** |
||
84 | * @var int |
||
85 | */ |
||
86 | protected $recordCount; |
||
87 | |||
88 | /** |
||
89 | * @param EntityManager $entityManager |
||
90 | * @param \stdClass $source |
||
91 | */ |
||
92 | 2 | public function __construct(EntityManager $entityManager, \stdClass $source) |
|
97 | |||
98 | /** |
||
99 | * @return \stdClass |
||
100 | */ |
||
101 | public function getRawData() |
||
105 | |||
106 | /** |
||
107 | * Get unique id |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | 2 | public function getId() |
|
115 | |||
116 | /** |
||
117 | * Get the record id |
||
118 | * |
||
119 | * @return integer |
||
120 | */ |
||
121 | 2 | public function getStoryId() |
|
125 | |||
126 | /** |
||
127 | * Get the databox id |
||
128 | * |
||
129 | * @return integer |
||
130 | */ |
||
131 | 2 | public function getDataboxId() |
|
135 | |||
136 | /** |
||
137 | * @return null|Subdef |
||
138 | */ |
||
139 | 2 | public function getThumbnail() |
|
147 | |||
148 | /** |
||
149 | * Last updated date |
||
150 | * |
||
151 | * @return \DateTime |
||
152 | */ |
||
153 | 2 | public function getUpdatedOn() |
|
157 | |||
158 | /** |
||
159 | * Creation date |
||
160 | * |
||
161 | * @return \DateTime |
||
162 | */ |
||
163 | 2 | public function getCreatedOn() |
|
167 | |||
168 | /** |
||
169 | * Get the record collection id |
||
170 | * |
||
171 | * @return integer |
||
172 | */ |
||
173 | 2 | public function getCollectionId() |
|
177 | |||
178 | /** |
||
179 | * Get the record UUID |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | 2 | public function getUuid() |
|
187 | |||
188 | /** |
||
189 | * @return int |
||
190 | */ |
||
191 | public function getRecordCount() |
||
198 | |||
199 | /** |
||
200 | * @return Record[]|ArrayCollection |
||
201 | */ |
||
202 | public function getRecords() |
||
212 | |||
213 | /** |
||
214 | * @return Metadata[]|ArrayCollection |
||
215 | */ |
||
216 | 2 | public function getMetadata() |
|
226 | |||
227 | /** |
||
228 | * @return RecordStatus[]|ArrayCollection |
||
229 | */ |
||
230 | public function getStatus() |
||
241 | |||
242 | /** |
||
243 | * @return RecordCaption[]|ArrayCollection |
||
244 | */ |
||
245 | public function getCaption() |
||
260 | } |
||
261 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: