ExtensionRegistry::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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