1 | <?php |
||
16 | class CacheKeyBuilder |
||
17 | { |
||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | const IDENTIFIER_SEPARATOR = '|'; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | const IDENTIFIER_PREFIX = ':'; |
||
27 | |||
28 | /** |
||
29 | * @var EtagHasherInterface |
||
30 | */ |
||
31 | protected $etag_hasher; |
||
32 | |||
33 | /** |
||
34 | * @var Registry|null |
||
35 | */ |
||
36 | protected $doctrine; |
||
37 | |||
38 | /** |
||
39 | * @param EtagHasherInterface $etag_hasher |
||
40 | */ |
||
41 | 9 | public function __construct(EtagHasherInterface $etag_hasher) |
|
45 | |||
46 | /** |
||
47 | * @param Registry $doctrine |
||
48 | * |
||
49 | * @return CacheKeyBuilder |
||
50 | */ |
||
51 | 9 | public function setDoctrine(Registry $doctrine) |
|
57 | |||
58 | /** |
||
59 | * @param object $entity |
||
60 | * |
||
61 | * @return string|null |
||
62 | */ |
||
63 | 4 | public function getEntityAlias($entity) |
|
85 | |||
86 | /** |
||
87 | * @param object $entity |
||
88 | * |
||
89 | * @return string|null |
||
90 | */ |
||
91 | 4 | public function getEntityIdentifier($entity) |
|
105 | |||
106 | /** |
||
107 | * @param Response $response |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | 1 | public function getEtag(Response $response) |
|
115 | } |
||
116 |
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 implementation 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 interface: