TrustAttestationTypeVoter::voteOnTrust()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

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