Passed
Push — master ( 78936a...47c5f2 )
by Smoren
02:13
created

NestedArrayStorage::isset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Smoren\NestedAccessor\Components;
4
5
use Smoren\NestedAccessor\Exceptions\NestedAccessorException;
6
use Smoren\NestedAccessor\Factories\NestedAccessorFactory;
7
use Smoren\NestedAccessor\Interfaces\NestedAccessorInterface;
8
9
/**
10
 * Storage with nested accessor interface
11
 * @author Smoren <[email protected]>
12
 */
13
class NestedArrayStorage 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
53
    /**
54
     * {@inheritDoc}
55
     */
56
    public function append($path, $value, bool $strict = true): self
57
    {
58
        $this->nestedAccessor->append($path, $value, $strict);
59
        return $this;
60
    }
61
62
    /**
63
     * {@inheritDoc}
64
     */
65
    public function exist($path): bool
66
    {
67
        return $this->nestedAccessor->exist($path);
68
    }
69
70
    /**
71
     * {@inheritDoc}
72
     */
73
    public function isset($path): bool
74
    {
75
        return $this->nestedAccessor->isset($path);
76
    }
77
}
78