1 | <?php |
||
12 | class routes |
||
13 | { |
||
14 | /** @var \phpbb\cache\driver\driver_interface */ |
||
15 | protected $cache; |
||
16 | |||
17 | /** @var \phpbb\config\config */ |
||
18 | protected $config; |
||
19 | |||
20 | /** @var \blitze\sitemaker\services\blocks\factory */ |
||
21 | protected $block_factory; |
||
22 | |||
23 | /** @var \blitze\sitemaker\model\mapper_factory */ |
||
24 | protected $mapper_factory; |
||
25 | |||
26 | /** |
||
27 | * Constructor |
||
28 | * |
||
29 | * @param \phpbb\cache\driver\driver_interface $cache Cache driver interface |
||
30 | * @param \phpbb\config\config $config Config object |
||
31 | * @param \blitze\sitemaker\services\blocks\factory $block_factory Blocks factory object |
||
32 | * @param \blitze\sitemaker\model\mapper_factory $mapper_factory Mapper factory object |
||
33 | */ |
||
34 | public function __construct(\phpbb\cache\driver\driver_interface $cache, \phpbb\config\config $config, \blitze\sitemaker\services\blocks\factory $block_factory, \blitze\sitemaker\model\mapper_factory $mapper_factory) |
||
41 | |||
42 | /** |
||
43 | * @param string $current_route |
||
44 | * @param int $style_id |
||
45 | * @param bool|false $edit_mode |
||
46 | * @return array |
||
47 | */ |
||
48 | public function get_route_info($current_route, $style_id, $edit_mode = false) |
||
61 | |||
62 | /** |
||
63 | * @param array $route_info |
||
64 | * @param int $style_id |
||
65 | * @param bool $edit_mode |
||
66 | * @return array |
||
67 | */ |
||
68 | public function get_blocks_for_route(array $route_info, $style_id, $edit_mode) |
||
75 | |||
76 | /** |
||
77 | * Clear blocks cache |
||
78 | */ |
||
79 | public function clear_cache() |
||
84 | |||
85 | /** |
||
86 | * @param bool $edit_mode |
||
87 | * @return array |
||
88 | */ |
||
89 | protected function _get_cached_blocks($edit_mode) |
||
99 | |||
100 | /** |
||
101 | * @return array |
||
102 | */ |
||
103 | protected function _get_all_blocks() |
||
128 | |||
129 | /** |
||
130 | * @return array|mixed |
||
131 | */ |
||
132 | protected function _get_all_routes() |
||
152 | |||
153 | /** |
||
154 | * @param array $all_routes |
||
155 | * @param string $current_route |
||
156 | * @param int $style_id |
||
157 | * @param bool $edit_mode |
||
158 | * @return array |
||
159 | */ |
||
160 | protected function _get_default_route_info(array $all_routes, $current_route, $style_id, $edit_mode) |
||
174 | |||
175 | /** |
||
176 | * @param array $route_info |
||
177 | * @param int $style_id |
||
178 | * @param bool $edit_mode |
||
179 | * @return int |
||
180 | */ |
||
181 | protected function _get_display_route_id(array $route_info, $style_id, $edit_mode) |
||
192 | |||
193 | /** |
||
194 | * @param array $blocks |
||
195 | * @param bool $edit_mode |
||
196 | */ |
||
197 | protected function _cache_block(array $blocks, $edit_mode) |
||
204 | } |
||
205 |
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: