HttpsCertificateAuthorityRule   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A doValidate() 0 10 4
1
<?php
2
3
namespace whm\Smoke\Rules\Http;
4
5
use whm\Smoke\Rules\ValidationFailedException;
6
7
/**
8
 * This rule checks if a given https certificate is cretaed by a special authority.
9
 */
10
class HttpsCertificateAuthorityRule extends HttpsRule
11
{
12
    private $authorityName;
13
14
    /**
15
     * @param string $authorityName authority name
16
     */
17
    public function init($authorityName)
18
    {
19
        $this->authorityName = $authorityName;
20
    }
21
22
    protected function doValidate($certInfo)
23
    {
24
        if (array_key_exists('issuer', $certInfo) and array_key_exists('CN', $certInfo['issuer'])) {
25
            if ($certInfo['issuer']['CN'] !== $this->authorityName) {
26
                throw new ValidationFailedException('Expected authority was "' . $this->authorityName . '", "' . $certInfo['issuer']['CN'] . '" found.');
27
            }
28
        } else {
29
            throw new ValidationFailedException('Expected authority was "' . $this->authorityName . '". No authority found.');
30
        }
31
    }
32
}
33