Failed Conditions
Push — master ( e7b6d0...f491f4 )
by Denis
03:14
created

ConditionManager::key()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types = 1);
2
3
namespace Artprima\QueryFilterBundle\Query;
4
5
use Artprima\QueryFilterBundle\Query\Condition\ConditionInterface;
6
7
/**
8
 * Class ConditionManager
9
 *
10
 * @author Denis Voytyuk <[email protected]>
11
 *
12
 * @package Artprima\QueryFilterBundle\Query
13
 */
14
class ConditionManager implements \ArrayAccess, \Iterator
15
{
16
    /**
17
     * @var ConditionInterface[]
18
     */
19
    private $conditions = [];
20
21 4
    public function add(ConditionInterface $condition, string $name): void
22
    {
23 4
        $this->conditions[$name] = $condition;
24 4
    }
25
26
    /**
27
     * @return ConditionInterface[]
28
     */
29
    public function all(): array
30
    {
31
        return $this->conditions;
32
    }
33
34 4
    public function offsetExists($offset)
35
    {
36 4
        return array_key_exists($offset, $this->conditions);
37
    }
38
39 4
    public function offsetGet($offset)
40
    {
41 4
        return $this->offsetExists($offset) ? $this->conditions[$offset] : null;
42
    }
43
44
    public function offsetSet($offset, $value)
45
    {
46
        if ($offset === null) {
47
            $this->conditions[] = $value;
48
        } else {
49
            $this->conditions[$offset] = $value;
50
        }
51
    }
52
53
    public function offsetUnset($offset) {
54
        unset($this->conditions[$offset]);
55
    }
56
57
    public function rewind() {
58
        return reset($this->conditions);
59
    }
60
61
    public function current() {
62
        return current($this->conditions);
63
    }
64
65
    public function key() {
66
        return key($this->conditions);
67
    }
68
69
    public function next() {
70
        return next($this->conditions);
71
    }
72
73
    public function valid() {
74
        return key($this->conditions) !== null;
75
    }
76
}
77