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   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 42
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A readFromFile() 0 4 1
A readFromUrl() 0 12 1
A certResourceToString() 0 8 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