1 | <?php |
||
22 | class TaggablePool extends Pool |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * The tags associated with this pool. |
||
27 | * @var array|null |
||
28 | */ |
||
29 | protected $tags = null; |
||
30 | |||
31 | /** |
||
32 | * @var CacheAdapter |
||
33 | */ |
||
34 | protected $cache_adapter; |
||
35 | |||
36 | /** |
||
37 | * Constructor. |
||
38 | */ |
||
39 | 7 | public function __construct(CacheItemPool $cache_item_pool) |
|
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | 2 | protected function setItemProperties( |
|
62 | |||
63 | /** |
||
64 | * Retrieves the cache keys for the given tag. |
||
65 | * |
||
66 | * @param string $tag The cache tag to retrieve. |
||
67 | * @return array Returns an array of cache keys. |
||
68 | */ |
||
69 | 2 | public function getMultipleByTag($tag) |
|
82 | |||
83 | /** |
||
84 | * Removes all the cached entries associated with the given tag names. |
||
85 | * |
||
86 | * @param array $tags An array of tag names (string). |
||
87 | * @return bool |
||
88 | */ |
||
89 | 2 | public function clearByTags(array $tags) |
|
93 | |||
94 | /** |
||
95 | * Sets this pool tags. |
||
96 | * |
||
97 | * @param array|null $tags |
||
98 | * @return TaggableItem The invoked object. |
||
99 | */ |
||
100 | 5 | public function setTags(array $tags=null) |
|
106 | |||
107 | /** |
||
108 | * Returns this pool tags. |
||
109 | * |
||
110 | * @return array|null |
||
111 | */ |
||
112 | 1 | public function getTags() |
|
116 | } |
||
117 |
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: