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