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 ( 21cab8...4aea99 )
by Nick
01:38
created

CommonNameValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Punkstar\Ssl\Validator;
4
5
use Punkstar\Ssl\Certificate;
6
7
class CommonNameValidator
8
{
9
    /**
10
     * @var Certificate
11
     */
12
    private $certificate;
13
    
14 2
    public function __construct(Certificate $certificate)
15
    {
16 2
        $this->certificate = $certificate;
17 2
    }
18
    
19 2
    public function isValid($domain) : bool
20
    {
21 2
        foreach ($this->getNameVariations($domain) as $nameVariation) {
22 2
            if (in_array($nameVariation, $this->getAllowedNames(), true)) {
23 2
                return true;
24
            }
25
        }
26
        
27 2
        return false;
28
    }
29
    
30 2
    private function getAllowedNames() : array
31
    {
32
        // Add any SANS that might be on the certificate.
33 2
        $allowedNames = $this->certificate->sans();
34
    
35 2
        $sslCertSubject = $this->certificate->subject();
36
    
37
        // Add the common name from the certificate.
38 2
        if (isset($sslCertSubject['CN'])) {
39 2
            $allowedNames[] = $sslCertSubject['CN'];
40
        }
41
        
42 2
        return $allowedNames;
43
    }
44
    
45 2
    private function getNameVariations($domain) : array
46
    {
47 2
        $nameVariations = [$domain];
48
    
49
        // If we're looking at a subdomain then check for wildcards.
50 2
        if (substr_count($domain, '.') >= 2) {
51 2
            $nameVariations[] = '*' . substr($domain, strpos($domain, '.'));
52
        }
53
        
54 2
        return $nameVariations;
55
    }
56
}
57