Conditions | 3 |
Paths | 4 |
Total Lines | 28 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 3.0593 |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | 1 | public function readFromUrl($url) |
|
15 | { |
||
16 | 1 | $urlHost = parse_url($url, PHP_URL_HOST); |
|
17 | |||
18 | 1 | if ($urlHost === null) { |
|
19 | $urlHost = $url; |
||
20 | } |
||
21 | |||
22 | 1 | $streamContext = stream_context_create(array( |
|
23 | "ssl" => array( |
||
24 | 1 | "capture_peer_cert" => TRUE, |
|
25 | 1 | "verify_peer" => FALSE, |
|
26 | "verify_peer_name" => FALSE |
||
27 | 1 | ) |
|
28 | 1 | )); |
|
29 | |||
30 | 1 | $stream = @stream_socket_client("ssl://" . $urlHost . ":443", $errorNumber, $errorString, self::CONNECTION_TIMEOUT, STREAM_CLIENT_CONNECT, $streamContext); |
|
31 | |||
32 | 1 | if ($stream) { |
|
33 | 1 | $streamParams = stream_context_get_params($stream); |
|
34 | |||
35 | 1 | $certResource = $streamParams['options']['ssl']['peer_certificate']; |
|
36 | |||
37 | 1 | return new Certificate($this->certResourceToString($certResource)); |
|
38 | } else { |
||
39 | throw new Exception(sprintf("Unable to connect to %s", $urlHost)); |
||
40 | } |
||
41 | } |
||
42 | |||
70 |