1 | <?php |
||
8 | class MemcacheFactory extends AbstractFactory |
||
9 | { |
||
10 | const MODULE_NAME = 'memcache'; |
||
11 | |||
12 | public function getModuleName() |
||
16 | |||
17 | /** |
||
18 | * @return \Memcache |
||
19 | */ |
||
20 | public function getMemcacheAdapter() |
||
24 | |||
25 | /** |
||
26 | * @param CacheProvider $cacheProvider |
||
27 | * |
||
28 | * @return CacheProvider |
||
29 | */ |
||
30 | protected function decorateWithConnectable(CacheProvider $cacheProvider) |
||
40 | |||
41 | /** |
||
42 | * @param Config $config |
||
43 | * |
||
44 | * @return bool |
||
45 | */ |
||
46 | protected function isValidConfig(Config $config) |
||
59 | } |
||
60 |
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: