Condition::valid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php declare(strict_types=1);
2
namespace samsonframework\orm;
3
4
/**
5
 * Query condition arguments group.
6
 *
7
 * @author Vitaly Iegorov <[email protected]>
8
 */
9
class Condition implements ConditionInterface
10
{
11
    /** @var string Relation logic between arguments */
12
    public $relation = ConditionInterface::CONJUNCTION;
13
14
    /** @var Argument[] Collection of condition arguments */
15
    protected $arguments = [];
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function addArgument(ArgumentInterface $argument)
21
    {
22
        // Add condition as current condition argument
23
        $this->arguments[] = $argument;
24
25
        return $this;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function addCondition(ConditionInterface $condition)
32
    {
33
        // Add condition as current condition argument
34
        $this->arguments[] = $condition;
35
36
        return $this;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function size()
43
    {
44
        return count($this->arguments);
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function add($argument, $value, $relation = ArgumentInterface::EQUAL)
51
    {
52
        if (is_string($argument)) {
53
            // Add new argument to arguments collection
54
            $this->arguments[] = new Argument($argument, $value, $relation);
55
        }
56
57
        return $this;
58
    }
59
60
    /**
61
     * Constructor
62
     * @param string $relation Relation type between arguments
63
     */
64
    public function __construct($relation = ConditionInterface::CONJUNCTION)
65
    {
66
        $this->relation = $relation;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function current()
73
    {
74
        return current($this->arguments);
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function next()
81
    {
82
        next($this->arguments);
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function key()
89
    {
90
        return key($this->arguments);
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function valid()
97
    {
98
        return key($this->arguments) !== null;
99
    }
100
101
    /**
102
     * {@inheritdoc}
103
     */
104
    public function rewind()
105
    {
106
        reset($this->arguments);
107
    }
108
}
109