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 ( e4100b...d22b8b )
by Nick
03:54
created

Certificate   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A validFrom() 0 6 1
A validTo() 0 6 1
A certName() 0 4 1
A subject() 0 4 1
A issuer() 0 4 1
A sans() 0 4 1
A signatureAlgorithm() 0 4 1
A toString() 0 4 1
A __toString() 0 4 1
A extractCertData() 0 10 2
1
<?php
2
3
namespace Punkstar\Ssl;
4
5
use DateTime;
6
use Punkstar\Ssl\Parser\SanParser;
7
8
class Certificate
9
{
10
    protected $rawCert;
11
    protected $certData;
12
13
    /**
14
     * @var SanParser
15
     */
16
    protected $sanParser;
17
18
    /**
19
     * Certificate constructor.
20
     *
21
     * @param string $certificate
22
     * @param SanParser $sanParser
23
     */
24 8
    public function __construct($certificate, SanParser $sanParser = null)
25
    {
26 8
        if ($sanParser === null) {
27 8
            $sanParser = new SanParser();
28 8
        }
29
30 8
        $this->sanParser = $sanParser;
31
32 8
        $this->rawCert = $certificate;
33 8
        $this->certData = $this->extractCertData($certificate);
34 7
        $this->sanParser = $sanParser;
35 7
    }
36
37
    /**
38
     * @return DateTime
39
     */
40 3
    public function validFrom()
41
    {
42 3
        $date = new DateTime();
43 3
        $date->setTimestamp($this->certData['validFrom_time_t']);
44 3
        return $date;
45
    }
46
47
    /**
48
     * @return DateTime
49
     */
50 3
    public function validTo()
51
    {
52 3
        $date = new DateTime();
53 3
        $date->setTimestamp($this->certData['validTo_time_t']);
54 3
        return $date;
55
    }
56
57
    /**
58
     * @return string
59
     */
60 3
    public function certName()
61
    {
62 3
        return $this->certData['name'];
63
    }
64
65
    /**
66
     * @return array
67
     */
68 3
    public function subject()
69
    {
70 3
        return $this->certData['subject'];
71
    }
72
73
    /**
74
     * @return array
75
     */
76 3
    public function issuer()
77
    {
78 3
        return $this->certData['issuer'];
79
    }
80
81
    /**
82
     * @return array
83
     */
84 3
    public function sans()
85
    {
86 3
        return $this->sanParser->parse($this->certData['extensions']['subjectAltName']);
87
    }
88
89
    /**
90
     * @return string
91
     */
92 3
    public function signatureAlgorithm()
93
    {
94 3
        return $this->certData['signatureTypeSN'];
95
    }
96
97
    /**
98
     * @return string
99
     */
100 6
    public function toString()
101
    {
102 6
        return $this->rawCert;
103
    }
104
105
    /**
106
     * @return string
107
     */
108 6
    public function __toString()
109
    {
110 6
        return $this->toString();
111
    }
112
113 8
    protected function extractCertData($certificate)
114
    {
115 8
        $parsedData = openssl_x509_parse($certificate);
116
117 8
        if ($parsedData === false) {
118 1
            throw new Exception("Unable to extract data from certificate.", Exception::MALFORMED_CERTIFICATE);
119
        }
120
121 7
        return $parsedData;
122
    }
123
}
124