Conditions | 1 |
Paths | 1 |
Total Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
22 | private function getCertifacateInformation($host) |
||
23 | { |
||
24 | $sslOptions = stream_context_create(array('ssl' => array('capture_peer_cert' => true))); |
||
25 | |||
26 | $request = @stream_socket_client( |
||
27 | 'ssl://' . $host . ':443', |
||
28 | $errno, |
||
29 | $errstr, |
||
30 | 30, |
||
31 | STREAM_CLIENT_CONNECT, |
||
32 | $sslOptions |
||
33 | ); |
||
34 | |||
35 | $content = @stream_context_get_params($request); |
||
36 | |||
37 | $certInfo = openssl_x509_parse($content['options']['ssl']['peer_certificate']); |
||
38 | |||
39 | return $certInfo; |
||
40 | } |
||
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: