Passed
Push — master ( 4f1a9b...c36f8b )
by Dmitry
01:12
created

Conditions::find()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

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