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 ( 1d2318...ea7909 )
by Nick
07:43
created

Reader   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 87.5%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 6
c 5
b 0
f 0
lcom 0
cbo 2
dl 0
loc 65
ccs 21
cts 24
cp 0.875
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B readFromUrl() 0 28 3
A readFromFile() 0 8 2
A certResourceToString() 0 8 1
1
<?php
2
3
namespace Punkstar\Ssl;
4
5
class Reader
6
{
7
    const CONNECTION_TIMEOUT = 30;
8
9
    /**
10
     * @param $url
11
     * @return Certificate
12
     * @throws Exception
13
     */
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
    
43
    /**
44
     * @param $file
45
     * @return Certificate
46
     * @throws Exception
47
     */
48 8
    public function readFromFile($file)
49
    {
50 8
        if (!file_exists($file)) {
51 1
            throw new Exception(sprintf("File '%s' does not exist", $file), Exception::FILE_NOT_FOUND);
52
        }
53
54 7
        return new Certificate(file_get_contents($file));
55
    }
56
57
    /**
58
     * @param $certResource
59
     * @return string
60
     */
61 1
    protected function certResourceToString($certResource)
62
    {
63 1
        $output = null;
64
65 1
        openssl_x509_export($certResource, $output);
66
67 1
        return $output;
68
    }
69
}
70