Passed
Push — master ( a80ba9...b999d2 )
by Smoren
01:46
created

NestedStorage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
wmc 3
eloc 8
c 1
b 1
f 1
dl 0
loc 38
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 4 1
A get() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
namespace Smoren\Schemator\Components;
4
5
use Smoren\Schemator\Exceptions\NestedAccessorException;
6
use Smoren\Schemator\Factories\NestedAccessorFactory;
7
use Smoren\Schemator\Interfaces\NestedAccessorInterface;
8
9
/**
10
 * Storage with nested accessor interface
11
 * @author Smoren <[email protected]>
12
 */
13
class NestedStorage implements NestedAccessorInterface
14
{
15
    /**
16
     * @var array<scalar, mixed> storage
17
     */
18
    protected array $storage;
19
    /**
20
     * @var NestedAccessorInterface nested accessor
21
     */
22
    protected NestedAccessorInterface $nestedAccessor;
23
24
    /**
25
     * @param array<scalar, mixed>|null $storage
26
     * @param NestedAccessorFactory|null $factory
27
     */
28
    public function __construct(?array $storage = null, ?NestedAccessorFactory $factory = null)
29
    {
30
        $this->storage = $storage ?? [];
31
        $this->nestedAccessor = ($factory ?? new NestedAccessorFactory())->create($this->storage);
32
    }
33
34
    /**
35
     * @inheritDoc
36
     * @throws NestedAccessorException
37
     */
38
    public function get($path, bool $strict = true)
39
    {
40
        return $this->nestedAccessor->get($path, $strict);
41
    }
42
43
    /**
44
     * @inheritDoc
45
     * @throws NestedAccessorException
46
     */
47
    public function set($path, $value, bool $strict = true): self
48
    {
49
        $this->nestedAccessor->set($path, $value, $strict);
50
        return $this;
51
    }
52
}