| 1 | <?php |
||
| 8 | class MemcachedFactory extends AbstractFactory |
||
| 9 | { |
||
| 10 | const MODULE_NAME = 'memcached'; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @return string |
||
| 14 | */ |
||
| 15 | public function getModuleName() |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @return \Memcache |
||
| 22 | */ |
||
| 23 | public function getMemcachedAdapter() |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param CacheProvider $cacheProvider |
||
| 30 | * |
||
| 31 | * @return CacheProvider |
||
| 32 | */ |
||
| 33 | protected function decorateWithConnectable(CacheProvider $cacheProvider) |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param Config $config |
||
| 46 | * |
||
| 47 | * @return bool |
||
| 48 | */ |
||
| 49 | protected function isValidConfig(Config $config) |
||
| 62 | } |
||
| 63 |
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: