TrustAttestationTypeVoter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 25
ccs 7
cts 9
cp 0.7778
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A voteOnTrust() 0 9 2
A __construct() 0 7 2
1
<?php
2
3
namespace MadWizard\WebAuthn\Policy\Trust\Voter;
4
5
use InvalidArgumentException;
6
use MadWizard\WebAuthn\Attestation\AttestationType;
7
use MadWizard\WebAuthn\Attestation\TrustAnchor\MetadataInterface;
8
use MadWizard\WebAuthn\Attestation\TrustPath\TrustPathInterface;
9
use MadWizard\WebAuthn\Policy\Trust\TrustVote;
10
use MadWizard\WebAuthn\Server\Registration\RegistrationResultInterface;
11
12
final class TrustAttestationTypeVoter implements TrustVoterInterface
13
{
14
    /**
15
     * @var string
16
     */
17
    private $trustedType;
18
19 18
    public function __construct(string $attestationType)
20
    {
21 18
        if (!AttestationType::isValidType($attestationType)) {
22
            throw new InvalidArgumentException(sprintf('Type "%s" is not a valid attestation type.', $attestationType));
23
        }
24
25 18
        $this->trustedType = $attestationType;
26 18
    }
27
28 1
    public function voteOnTrust(
29
        RegistrationResultInterface $registrationResult,
30
        TrustPathInterface $trustPath,
31
        ?MetadataInterface $metadata
32
    ): TrustVote {
33 1
        if ($registrationResult->getVerificationResult()->getAttestationType() === $this->trustedType) {
34
            return TrustVote::trusted();
35
        }
36 1
        return TrustVote::abstain();
37
    }
38
}
39