1 | <?php |
||
17 | class PublicKey extends Key implements PublicKeyInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var EcAdapter |
||
21 | */ |
||
22 | private $ecAdapter; |
||
23 | |||
24 | /** |
||
25 | * @var bool|false |
||
26 | */ |
||
27 | private $compressed; |
||
28 | |||
29 | /** |
||
30 | * @var resource |
||
31 | */ |
||
32 | private $pubkey_t; |
||
33 | |||
34 | /** |
||
35 | * @param EcAdapter $ecAdapter |
||
36 | * @param resource $secp256k1_pubkey_t |
||
37 | * @param bool|false $compressed |
||
38 | */ |
||
39 | 222 | public function __construct(EcAdapter $ecAdapter, $secp256k1_pubkey_t, bool $compressed = false) |
|
54 | |||
55 | /** |
||
56 | * @param BufferInterface $msg32 |
||
57 | * @param SignatureInterface $signature |
||
58 | * @return bool |
||
59 | */ |
||
60 | 148 | public function verify(BufferInterface $msg32, SignatureInterface $signature): bool |
|
68 | |||
69 | /** |
||
70 | * @param PublicKey $other |
||
71 | * @return bool |
||
72 | */ |
||
73 | 26 | private function doEquals(PublicKey $other): bool |
|
86 | |||
87 | /** |
||
88 | * @param PublicKeyInterface $other |
||
89 | * @return bool |
||
90 | */ |
||
91 | 26 | public function equals(PublicKeyInterface $other): bool |
|
96 | |||
97 | /** |
||
98 | * @return bool|false |
||
99 | */ |
||
100 | 92 | public function isCompressed(): bool |
|
104 | |||
105 | /** |
||
106 | * @return resource |
||
107 | */ |
||
108 | 82 | public function getResource() |
|
112 | |||
113 | /** |
||
114 | * @return resource |
||
115 | * @throws \Exception |
||
116 | */ |
||
117 | 3 | private function clonePubkey() |
|
134 | |||
135 | /** |
||
136 | * @param \GMP $tweak |
||
137 | * @return KeyInterface |
||
138 | * @throws \Exception |
||
139 | */ |
||
140 | 2 | public function tweakAdd(\GMP $tweak): KeyInterface |
|
152 | |||
153 | /** |
||
154 | * @param \GMP $tweak |
||
155 | * @return KeyInterface |
||
156 | * @throws \Exception |
||
157 | */ |
||
158 | 1 | public function tweakMul(\GMP $tweak): KeyInterface |
|
170 | |||
171 | /** |
||
172 | * @return BufferInterface |
||
173 | */ |
||
174 | 77 | public function getBuffer(): BufferInterface |
|
178 | } |
||
179 |
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: