Passed
Push — master ( 63b017...0b8308 )
by Denis
02:33
created

ConditionManager::offsetSet()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

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