GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 2fe0a7...d5b2cb )
by Nick
02:15
created

Reader::readFromUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Punkstar\Ssl;
4
5
class Reader
6
{
7
8
    /**
9
     * @param $url
10
     * @return Certificate
11
     */
12 1
    public function readFromUrl($url)
13
    {
14 1
        $urlHost = parse_url($url, PHP_URL_HOST);
15
16 1
        $streamContext = stream_context_create(array("ssl" => array("capture_peer_cert" => TRUE)));
17 1
        $stream = stream_socket_client("ssl://".$urlHost.":443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $streamContext);
18 1
        $streamParams = stream_context_get_params($stream);
19
20 1
        $certResource = $streamParams['options']['ssl']['peer_certificate'];
21
22 1
        return new Certificate($this->certResourceToString($certResource));
23
    }
24
25
    /**
26
     * @param $file
27
     * @return Certificate
28
     */
29 6
    public function readFromFile($file)
30
    {
31 6
        return new Certificate(file_get_contents($file));
32
    }
33
34
    /**
35
     * @param $certResource
36
     * @return string
37
     */
38 1
    protected function certResourceToString($certResource)
39
    {
40 1
        $output = null;
41
42 1
        openssl_x509_export($certResource, $output);
43
44 1
        return $output;
45
    }
46
}
47