| 1 | <?php | ||
| 15 | class RedisCache extends CacheItemPool | ||
| 16 | { | ||
| 17 | public function __construct() | ||
| 21 | |||
| 22 | /** | ||
| 23 | * Sets the redis instance to use. | ||
| 24 | * | ||
| 25 | * @param Redis $redis | ||
| 26 | * | ||
| 27 | * @return void | ||
| 28 | */ | ||
| 29 | public function setRedis(Redis $redis) | ||
| 33 | |||
| 34 | /** | ||
| 35 | * Gets the redis instance used by the cache. | ||
| 36 | * | ||
| 37 | * @return Redis|null | ||
| 38 | */ | ||
| 39 | public function getRedis() | ||
| 43 | } | ||
| 44 | 
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: