1 | <?php |
||
9 | abstract class HttpsRule implements Rule |
||
10 | { |
||
11 | public function validate(ResponseInterface $response) |
||
12 | { |
||
13 | if ('https' === $response->getUri()->getScheme()) { |
||
|
|||
14 | $certInfo = $this->getCertifacateInformation($response->getUri()->getHost()); |
||
15 | |||
16 | return $this->doValidate($certInfo); |
||
17 | } |
||
18 | } |
||
19 | |||
20 | abstract protected function doValidate($certInfo); |
||
21 | |||
22 | private function getCertifacateInformation($host) |
||
41 | } |
||
42 |
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: