TrustChainVoter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace MadWizard\WebAuthn\Policy\Trust\Voter;
4
5
use MadWizard\WebAuthn\Attestation\TrustAnchor\MetadataInterface;
6
use MadWizard\WebAuthn\Attestation\TrustAnchor\TrustPathValidatorInterface;
7
use MadWizard\WebAuthn\Attestation\TrustPath\TrustPathInterface;
8
use MadWizard\WebAuthn\Policy\Trust\TrustVote;
9
use MadWizard\WebAuthn\Server\Registration\RegistrationResultInterface;
10
11
final class TrustChainVoter implements TrustVoterInterface
12
{
13
    /**
14
     * @var TrustPathValidatorInterface
15
     */
16
    private $pathValidator;
17
18 18
    public function __construct(TrustPathValidatorInterface $pathVal)
19
    {
20 18
        $this->pathValidator = $pathVal;
21 18
    }
22
23 1
    public function voteOnTrust(
24
        RegistrationResultInterface $registrationResult,
25
        TrustPathInterface $trustPath,
26
        ?MetadataInterface $metadata
27
    ): TrustVote {
28 1
        if ($metadata === null) {
29 1
            return TrustVote::abstain();
30
        }
31
32
        $trustAnchors = $metadata->getTrustAnchors();
33
        foreach ($trustAnchors as $anchor) {
34
            if ($this->pathValidator->validate($trustPath, $anchor)) {
35
                return TrustVote::trusted();
36
            }
37
        }
38
        return TrustVote::abstain();
39
    }
40
}
41