MetadataBag   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 12 2
A get() 0 3 1
A __construct() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Thunder micro CLI framework.
7
 * (c) Jérémy Marodon <[email protected]>
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace RxThunder\Core\Model;
13
14
final class MetadataBag
15
{
16
    /** @psalm-var array<string, scalar>  */
17
    private array $parameters = [];
18
19
    /**
20
     * @psalm-param array<string, scalar> $parameters
21
     */
22 4
    public function __construct(array $parameters)
23
    {
24 4
        foreach ($parameters as $key => $value) {
25 3
            $this->add((string) $key, $value);
26
        }
27 3
    }
28
29
    /**
30
     * @psalm-param scalar $value
31
     */
32 3
    public function add(string $key, $value): self
33
    {
34 3
        if (!is_scalar($value)) {
35 1
            throw new \InvalidArgumentException(sprintf(
36 1
                'MetadataBag expect scalar value, %s given',
37 1
                gettype($value)
38
            ));
39
        }
40
41 2
        $this->parameters[$key] = $value;
42
43 2
        return $this;
44
    }
45
46
    /**
47
     * @psalm-return ?scalar
48
     */
49 2
    public function get(string $key)
50
    {
51 2
        return $this->parameters[$key] ?? null;
52
    }
53
}
54