AppIdExtension   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 12
dl 0
loc 29
ccs 15
cts 15
cp 1
rs 10
c 1
b 0
f 1
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parseResponse() 0 8 2
A processExtension() 0 12 4
A __construct() 0 3 1
1
<?php
2
3
namespace MadWizard\WebAuthn\Extension\AppId;
4
5
use MadWizard\WebAuthn\Exception\ExtensionException;
6
use MadWizard\WebAuthn\Exception\ParseException;
7
use MadWizard\WebAuthn\Extension\AbstractExtension;
8
use MadWizard\WebAuthn\Extension\ExtensionInputInterface;
9
use MadWizard\WebAuthn\Extension\ExtensionOutputInterface;
10
use MadWizard\WebAuthn\Extension\ExtensionProcessingContext;
11
use MadWizard\WebAuthn\Extension\ExtensionResponseInterface;
12
13
class AppIdExtension extends AbstractExtension
14
{
15 5
    public function __construct()
16
    {
17 5
        parent::__construct('appid');
18 5
    }
19
20 2
    public function parseResponse(ExtensionResponseInterface $extensionResponse): ExtensionOutputInterface
21
    {
22 2
        $extensionOutput = $extensionResponse->getClientExtensionOutput();
23 2
        if (!is_bool($extensionOutput)) {
24 1
            throw new ParseException('Expecting boolean value in appid extension output.');
25
        }
26
27 1
        return new AppIdExtensionOutput($extensionOutput);
28
    }
29
30 3
    public function processExtension(ExtensionInputInterface $input, ExtensionOutputInterface $output, ExtensionProcessingContext $context): void
31
    {
32 3
        if (!$input instanceof AppIdExtensionInput) {
33 1
            throw new ExtensionException('Expecting appid extension input to be AppIdExtensionInput.');
34
        }
35 2
        if (!$output instanceof AppIdExtensionOutput) {
36 1
            throw new ExtensionException('Expecting appid extension output to be AppIdExtensionOutput.');
37
        }
38
        // SPEC: Client extension output: If true, the AppID was used and thus, when verifying an assertion,
39
        // the Relying Party MUST expect the rpIdHash to be the hash of the AppID, not the RP ID.
40 1
        if ($output->getAppIdUsed()) {
41 1
            $context->setOverruledRpId($input->getAppId());
42
        }
43 1
    }
44
}
45