Registry::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of Monsieur Biz' Rich Editor plugin for Sylius.
5
 *
6
 * (c) Monsieur Biz <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace MonsieurBiz\SyliusRichEditorPlugin\UiElement\Metadata;
15
16
use MonsieurBiz\SyliusRichEditorPlugin\UiElement\Metadata;
17
use MonsieurBiz\SyliusRichEditorPlugin\UiElement\MetadataInterface;
18
19
final class Registry implements RegistryInterface
20
{
21
    /**
22
     * @var array|MetadataInterface[]
23
     */
24
    private array $metadata = [];
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function get(string $code): MetadataInterface
30
    {
31
        if (!\array_key_exists($code, $this->metadata)) {
32
            throw new \InvalidArgumentException(sprintf('Resource "%s" does not exist.', $code));
33
        }
34
35
        return $this->metadata[$code];
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function add(MetadataInterface $metadata): void
42
    {
43
        $this->metadata[$metadata->getCode()] = $metadata;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function addFromCodeAndConfiguration(string $code, array $configuration): void
50
    {
51
        $this->add(Metadata::fromCodeAndConfiguration($code, $configuration));
52
    }
53
}
54