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
Pull Request — master (#117)
by
unknown
01:06
created

Local::certificateAsString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\SslCertificate;
4
5
use Spatie\SslCertificate\Exceptions\CouldNotLoadLocalCertificate;
6
7
class Local
8
{
9
    private function parseCertificate(string $certificateString): SslCertificate
10
    {
11
        $certificateString = trim($certificateString);
12
13
        if (length($certificateString) === 0) {
14
            throw CouldNotLoadLocalCertificate::certificateStringIsEmpty();
15
        }
16
17
        $certificateFields = openssl_x509_parse($certificateString);
18
        if (! $certificateFields) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $certificateFields of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
19
            throw CouldNotLoadLocalCertificate::localCertificateParseFailed();
20
        }
21
22
        $fingerprint = openssl_x509_fingerprint($certificateString);
23
        $fingerprintSha256 = openssl_x509_fingerprint($certificateString, 'sha256');
24
25
        return new SslCertificate(
26
            $certificateFields,
27
            $fingerprint,
28
            $fingerprintSha256
29
        );
30
    }
31
32
    public static function certificateAsString(string $certificateString): SslCertificate
33
    {
34
        return (new static ())->parseCertificate($certificateString);
35
    }
36
37
    public static function certificateFromLocalPath(string $path): SslCertificate
38
    {
39
        if (! file_exists($path)) {
40
            throw CouldNotLoadLocalCertificate::certificatePathNotFound($path);
41
        }
42
43
        if (! is_readable($path)) {
44
            throw CouldNotLoadLocalCertificate::certificateFilePermissionInvalid($path);
45
        }
46
47
        $certificateString = file_get_contents($path);
48
        if (! $certificateString) {
49
            throw CouldNotLoadLocalCertificate::certificateFileReadFailed($path);
50
        }
51
52
        return (new static())->parseCertificate($certificateString);
53
    }
54
}
55