TrustChainVoter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 54.55%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 28
ccs 6
cts 11
cp 0.5455
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A voteOnTrust() 0 16 4
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