Completed
Pull Request — master (#1)
by Dmitry
01:58 queued 49s
created

Conditions::offsetSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SymfonyBundles\Pattern\ArrayConditions;
4
5
class Conditions implements ConditionsInterface
6
{
7
    public const FIND_SEPARATOR = '.';
8
9
    /**
10
     * @var array
11
     */
12
    protected $elements;
13
14
    /**
15
     * @param array $elements
16
     */
17
    public function __construct(array $elements = [])
18
    {
19
        $this->setElements($elements);
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function setElements(array $elements): void
26
    {
27
        $this->elements = $elements;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getElements(): array
34
    {
35
        return $this->elements;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function find(string $path, $default = null)
42
    {
43
        $element = $this->elements;
44
45
        foreach (\explode(static::FIND_SEPARATOR, $path) as $node) {
46
            if (isset($element[$node])) {
47
                $element = $element[$node];
48
            } else {
49
                return $default;
50
            }
51
        }
52
53
        return $element;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function offsetExists($offset)
60
    {
61
        return \array_key_exists($offset, $this->elements);
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function offsetGet($offset)
68
    {
69
        return $this->elements[$offset];
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function offsetSet($offset, $value)
76
    {
77
        $this->elements[$offset] = $value;
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function offsetUnset($offset)
84
    {
85
        unset($this->elements[$offset]);
86
    }
87
}
88