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 ( fb3a62...ec23f8 )
by Orlando
01:04
created

CER   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 68
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A decode() 0 11 1
A getCertificateNumber() 0 13 2
A getExpirationDate() 0 6 1
A getInitialDate() 0 6 1
A parseCertificate() 0 4 1
A dateFormat() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the cfdi-certificate project.
5
 *
6
 * (c) Kinedu
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Kinedu\CFDI\Certificate;
13
14
class CER extends Certificate
15
{
16
    /** @var string */
17
    protected $cerFile;
18
19
    /** @var integer */
20
    protected $chunkLength = 64;
21
22
    /** @var string */
23
    public $decodeExtension = 'cer.pem';
24
25
    public function __construct(string $cerFile)
26
    {
27
        $this->cerFile = file_get_contents(
28
            $this->getOriginalRouteFile($cerFile)
29
        );
30
    }
31
32
    public function decode(): string
33
    {
34
        $prefix = "-----BEGIN CERTIFICATE-----\n";
35
        $suffix = "-----END CERTIFICATE-----\n";
36
37
        $pem = base64_encode($this->cerFile);
38
        $pem = chunk_split($pem, $this->chunkLength, "\n") ;
39
        $pem = $prefix.$pem.$suffix;
40
41
        return $pem;
42
    }
43
44
    public function getCertificateNumber(): string
45
    {
46
        $data = $this->parseCertificate();
47
        $data = str_split($data['serialNumberHex'], 2);
48
49
        $serialNumber = null;
50
51
        for ($i = 0; $i < sizeof($data); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function sizeof() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
52
            $serialNumber .= substr($data[$i], 1);
53
        }
54
55
        return $serialNumber;
56
    }
57
58
    public function getExpirationDate(): string
59
    {
60
        $data = $this->parseCertificate();
61
62
        return $this->dateFormat($data['validTo_time_t']);
63
    }
64
65
    public function getInitialDate(): string
66
    {
67
        $data = $this->parseCertificate();
68
69
        return $this->dateFormat($data['validFrom_time_t']);
70
    }
71
72
    protected function parseCertificate(): array
73
    {
74
        return openssl_x509_parse($this->decode());
75
    }
76
77
    protected function dateFormat(string $date): string
78
    {
79
        return date('Y-m-d H:i:s', $date);
80
    }
81
}
82