CertificateTrustPath::fromBase64List()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
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