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   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 50
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isValid() 0 10 3
A getAllowedNames() 0 14 2
A getNameVariations() 0 11 2
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