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

ConditionManager   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 25.92%

Importance

Changes 0
Metric Value
dl 0
loc 61
ccs 7
cts 27
cp 0.2592
rs 10
c 0
b 0
f 0
wmc 13

11 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetGet() 0 3 2
A key() 0 2 1
A next() 0 2 1
A rewind() 0 2 1
A offsetExists() 0 3 1
A current() 0 2 1
A all() 0 3 1
A valid() 0 2 1
A offsetSet() 0 6 2
A offsetUnset() 0 2 1
A add() 0 3 1
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