1 | <?php |
||
17 | class Feed |
||
18 | { |
||
19 | |||
20 | 1 | public static function fromList(EntityManager $entityManager, array $values) |
|
30 | |||
31 | 2 | public static function fromValue(EntityManager $entityManager, \stdClass $value) |
|
35 | |||
36 | /** |
||
37 | * @var EntityManager |
||
38 | */ |
||
39 | protected $entityManager; |
||
40 | |||
41 | /** |
||
42 | * @var \stdClass |
||
43 | */ |
||
44 | protected $source; |
||
45 | |||
46 | /** |
||
47 | * @var \DateTime|null |
||
48 | */ |
||
49 | protected $createdOn; |
||
50 | |||
51 | /** |
||
52 | * @var \DateTime|null |
||
53 | */ |
||
54 | protected $updatedOn; |
||
55 | |||
56 | /** |
||
57 | * @param EntityManager $entityManager |
||
58 | * @param \stdClass $source |
||
59 | */ |
||
60 | 2 | public function __construct(EntityManager $entityManager, \stdClass $source) |
|
65 | |||
66 | /** |
||
67 | * @return \stdClass |
||
68 | */ |
||
69 | public function getRawData() |
||
73 | 2 | ||
74 | /** |
||
75 | * The feed id |
||
76 | * |
||
77 | * @return integer |
||
78 | */ |
||
79 | public function getId() |
||
83 | 2 | ||
84 | /** |
||
85 | * The feed title |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | public function getTitle() |
||
93 | 2 | ||
94 | /** |
||
95 | * The feed icon |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | public function getIcon() |
||
103 | 2 | ||
104 | /** |
||
105 | * The feed subtitle |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | public function getSubTitle() |
||
113 | 2 | ||
114 | /** |
||
115 | * Get the total entries of the feed |
||
116 | * |
||
117 | * @return integer |
||
118 | */ |
||
119 | public function getTotalEntries() |
||
123 | 2 | ||
124 | /** |
||
125 | * Creation date |
||
126 | * |
||
127 | * @return \DateTime |
||
128 | */ |
||
129 | public function getCreatedOn() |
||
133 | 2 | ||
134 | /** |
||
135 | * Last updated date |
||
136 | * |
||
137 | * @return \DateTime |
||
138 | */ |
||
139 | public function getUpdatedOn() |
||
143 | 2 | ||
144 | /** |
||
145 | * Tell whether the feed is public or not |
||
146 | * |
||
147 | * @return Boolean |
||
148 | */ |
||
149 | public function isPublic() |
||
153 | 2 | ||
154 | /** |
||
155 | * Tell whether the feed is a read only feed |
||
156 | * |
||
157 | * @return Boolean |
||
158 | */ |
||
159 | public function isReadonly() |
||
163 | 2 | ||
164 | /** |
||
165 | * Tell whether the feed is deletable |
||
166 | * |
||
167 | * @return Boolean |
||
168 | */ |
||
169 | public function isDeletable() |
||
173 | |||
174 | /** |
||
175 | * @param int $offset |
||
176 | * @param int $perPage |
||
177 | * @return FeedEntry[]|ArrayCollection |
||
178 | */ |
||
179 | public function getEntries($offset = 0, $perPage = 0) |
||
185 | } |
||
186 |
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: