Test Setup Failed
Pull Request — master (#1)
by Dmitry
02:02 queued 58s
created

Conditions::offsetUnset()   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 1
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
    /**
8
     * @var array
9
     */
10
    protected $elements;
11
12
    /**
13
     * @param array $elements
14
     */
15
    public function __construct(array $elements = [])
16
    {
17
        $this->setElements($elements);
18
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function setElements(array $elements): void
24
    {
25
        $this->elements = $elements;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function getElements(): array
32
    {
33
        return $this->elements;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function find(string $path, $default = null)
40
    {
41
        $element = $this->elements;
42
43
        foreach (\explode(static::FIND_SEPARATOR, $path) as $node) {
44
            if (isset($element[$node])) {
45
                $element = $element[$node];
46
            } else {
47
                return $default;
48
            }
49
        }
50
51
        return $element;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function offsetExists($offset)
58
    {
59
        return \array_key_exists($offset, $this->elements);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function offsetGet($offset)
66
    {
67
        return $this->elements[$offset];
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function offsetSet($offset, $value)
74
    {
75
        $this->elements[$offset] = $value;
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function offsetUnset($offset)
82
    {
83
        unset($this->elements[$offset]);
84
    }
85
}
86