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 ( 81a457...ca7640 )
by Daniel
03:05
created

SslChain   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 146
Duplicated Lines 5.48 %

Coupling/Cohesion

Components 4
Dependencies 1

Test Coverage

Coverage 96.3%

Importance

Changes 0
Metric Value
dl 8
loc 146
ccs 52
cts 54
cp 0.963
rs 10
c 0
b 0
f 0
wmc 23
lcom 4
cbo 1

19 Methods

Rating   Name   Duplication   Size   Complexity  
A getIssuerCommonName() 0 4 1
A getSerialNumber() 0 4 1
A validFromDate() 0 4 1
A expirationDate() 0 4 1
A getSignatureAlgorithm() 0 4 1
A isExpired() 0 4 1
A isValidUntil() 0 8 2
A setValidFromDate() 0 4 1
A setValidToDate() 0 4 1
A __construct() 0 12 1
A getLocationName() 0 4 1
A getOrganizationName() 0 4 1
A getOrganizationUnitName() 0 4 1
A getCommonName() 0 4 1
A getHash() 0 4 1
A getIssuerLocationName() 0 4 1
A getIssuerOrganizationName() 0 4 1
A getIssuerOrganizationUnitName() 0 10 3
A isValid() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace LiquidWeb\SslCertificate;
4
5
use Carbon\Carbon;
6
use phpseclib\Math\BigInteger;
7
8
class SslChain
9
{
10
    /** @var string */
11
    protected $name;
12
13
    /** @var array */
14
    protected $subject;
15
16
    /** @var string */
17
    protected $hash;
18
19
    /** @var array */
20
    protected $issuer;
21
22
    /** @var string */
23
    protected $version;
24
25
    /** @var BigInteger */
26
    protected $serial;
27
28
    /** @var Carbon */
29
    protected $validFrom;
30
31
    /** @var Carbon */
32
    protected $validTo;
33
34
    /** @var string */
35
    protected $signatureType;
36
37 41
    private static function setValidFromDate($utcInput): Carbon
38
    {
39 41
        return Carbon::createFromTimestampUTC($utcInput);
40
    }
41
42 41
    private static function setValidToDate($utcInput): Carbon
43
    {
44 41
        return Carbon::createFromTimestampUTC($utcInput);
45
    }
46
47 41
    public function __construct(array $chainInput)
48
    {
49 41
        $this->name = $chainInput['name'];
50 41
        $this->subject = $chainInput['subject'];
51 41
        $this->hash = $chainInput['hash'];
52 41
        $this->issuer = $chainInput['issuer'];
53 41
        $this->version = $chainInput['version'];
54 41
        $this->serial = new BigInteger($chainInput['serialNumber']);
55 41
        $this->validFrom = self::setValidFromDate($chainInput['validFrom_time_t']);
56 41
        $this->validTo = self::setValidToDate($chainInput['validTo_time_t']);
57 41
        $this->signatureType = $chainInput['signatureTypeSN'];
58 41
    }
59
60 1
    public function getLocationName(): string
61
    {
62 1
        return $this->subject['C'] ?? '';
63
    }
64
65 1
    public function getOrganizationName(): string
66
    {
67 1
        return $this->subject['O'] ?? '';
68
    }
69
70 1
    public function getOrganizationUnitName(): string
71
    {
72 1
        return $this->subject['OU'] ?? '';
73
    }
74
75 1
    public function getCommonName(): string
76
    {
77 1
        return $this->subject['CN'] ?? '';
78
    }
79
80 1
    public function getHash(): string
81
    {
82 1
        return $this->hash;
83
    }
84
85 1
    public function getIssuerLocationName(): string
86
    {
87 1
        return $this->issuer['C'] ?? '';
88
    }
89
90 1
    public function getIssuerOrganizationName(): string
91
    {
92 1
        return $this->issuer['O'] ?? '';
93
    }
94
95 2
    public function getIssuerOrganizationUnitName(): string
96
    {
97 2
        if (isset($this->issuer['OU']) === true) {
98 2
            if (is_array($this->issuer['OU']) === true) {
99 1
                return $this->issuer['OU'][0] ?? '';
100
            }
101
        }
102
103 1
        return $this->issuer['OU'] ?? '';
104
    }
105
106 1
    public function getIssuerCommonName(): string
107
    {
108 1
        return $this->issuer['CN'] ?? '';
109
    }
110
111 1
    public function getSerialNumber(): string
112
    {
113 1
        return strtoupper($this->serial->toHex());
114
    }
115
116 2
    public function validFromDate(): Carbon
117
    {
118 2
        return $this->validFrom;
119
    }
120
121 4
    public function expirationDate(): Carbon
122
    {
123 4
        return $this->validTo;
124
    }
125
126 1
    public function getSignatureAlgorithm(): string
127
    {
128 1
        return $this->signatureType;
129
    }
130
131 1
    public function isExpired(): bool
132
    {
133 1
        return $this->expirationDate()->isPast();
134
    }
135
136 1 View Code Duplication
    public function isValid()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
137
    {
138 1
        if (Carbon::now()->between($this->validFromDate(), $this->expirationDate()) === false) {
139
            return false;
140
        }
141
142 1
        return true;
143
    }
144
145 1
    public function isValidUntil(Carbon $carbon): bool
146
    {
147 1
        if ($this->expirationDate()->gt($carbon) === true) {
148 1
            return false;
149
        }
150
151
        return $this->isValid();
152
    }
153
}
154