QualifiedCertificate::subject()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Bip70\X509;
6
7
use Bip70\Exception\X509Exception;
8
use X501\ASN1\Name;
9
use X509\CertificationPath\CertificationPath;
10
use X509\CertificationPath\PathValidation\PathValidationResult;
11
12
class QualifiedCertificate
13
{
14
    /**
15
     * @var CertificationPath
16
     */
17
    private $path;
18
19
    /**
20
     * @var PathValidationResult
21
     */
22
    private $validationResult;
23
24
    /**
25
     * QualifiedCertificate constructor.
26
     * @param CertificationPath $path
27
     * @param PathValidationResult $result
28
     * @throws X509Exception
29
     */
30 6
    public function __construct(CertificationPath $path, PathValidationResult $result)
31
    {
32 6
        if (!$result->certificate()->equals($path->endEntityCertificate())) {
33 1
            throw new X509Exception("CertificationPath entity certificate must match PathValidationResult certificate");
34
        }
35
36 6
        $this->path = $path;
37 6
        $this->validationResult = $result;
38 6
    }
39
40
    /**
41
     * @return Name
42
     */
43 1
    public function subject(): Name
44
    {
45 1
        return $this->path->endEntityCertificate()->tbsCertificate()->subject();
46
    }
47
48
    /**
49
     * @return CertificationPath
50
     */
51 3
    public function getPath(): CertificationPath
52
    {
53 3
        return $this->path;
54
    }
55
56
    /**
57
     * @return PathValidationResult
58
     */
59 4
    public function getValidationResult(): PathValidationResult
60
    {
61 4
        return $this->validationResult;
62
    }
63
}
64