CertificateTrustPath   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 58.81%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 49
ccs 10
cts 17
cp 0.5881
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A fromPemList() 0 5 1
A __construct() 0 8 3
A getCertificates() 0 3 1
A fromBase64List() 0 5 1
A asPemList() 0 5 1
1
<?php
2
3
namespace MadWizard\WebAuthn\Attestation\TrustPath;
4
5
use InvalidArgumentException;
6
use MadWizard\WebAuthn\Pki\X509Certificate;
7
8
final class CertificateTrustPath implements TrustPathInterface
9
{
10
    /**
11
     * @var X509Certificate[]
12
     */
13
    private $certificates;
14
15 8
    public function __construct(X509Certificate ...$certificates)
16
    {
17 8
        foreach ($certificates as $c) {
18 8
            if (!($c instanceof X509Certificate)) {
19
                throw new InvalidArgumentException(sprintf('Expecting array of X509Certificate objects.'));
20
            }
21
        }
22 8
        $this->certificates = $certificates;
23 8
    }
24
25
    public static function fromPemList(array $x5c): self
26
    {
27
        return new CertificateTrustPath(...array_map(static function (string $s): X509Certificate {
28
            return X509Certificate::fromPem($s);
29
        }, $x5c));
30
    }
31
32
    public static function fromBase64List(array $x5c): self
33
    {
34
        return new CertificateTrustPath(...array_map(static function (string $s): X509Certificate {
35
            return X509Certificate::fromBase64($s);
36
        }, $x5c));
37
    }
38
39
    /**
40
     * @return X509Certificate[]
41
     */
42 2
    public function getCertificates(): array
43
    {
44 2
        return $this->certificates;
45
    }
46
47
    /**
48
     * Returns certificates as a list of PEM encoded strings (including armor).
49
     *
50
     * @return string[]
51
     */
52 5
    public function asPemList(): array
53
    {
54
        return array_map(static function (X509Certificate $cert): string {
55 5
            return $cert->asPem();
56 5
        }, $this->certificates);
57
    }
58
}
59