ExtensionRegistry   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 15.38%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
dl 0
loc 27
ccs 2
cts 13
cp 0.1538
rs 10
c 1
b 0
f 1
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getExtension() 0 7 2
A addExtension() 0 7 2
A __construct() 0 2 1
1
<?php
2
3
namespace MadWizard\WebAuthn\Extension;
4
5
use MadWizard\WebAuthn\Exception\ConfigurationException;
6
use MadWizard\WebAuthn\Exception\UnsupportedException;
7
8
class ExtensionRegistry implements ExtensionRegistryInterface
9
{
10
    /**
11
     * @var array<string, ExtensionInterface>
12
     */
13
    private $extensions = [];
14
15 18
    public function __construct()
16
    {
17 18
    }
18
19
    public function addExtension(ExtensionInterface $extension): void
20
    {
21
        $id = $extension->getIdentifier();
22
        if (isset($this->extensions[$id])) {
23
            throw new ConfigurationException(sprintf('Extension with identifier %s is already registered.', $id));
24
        }
25
        $this->extensions[$id] = $extension;
26
    }
27
28
    public function getExtension(string $extensionId): ExtensionInterface
29
    {
30
        $ext = $this->extensions[$extensionId] ?? null;
31
        if ($ext === null) {
32
            throw new UnsupportedException(sprintf('Extension with id %s not supported.', $extensionId));
33
        }
34
        return $ext;
35
    }
36
}
37