Completed
Push — master ( 12ee63...317189 )
by Vitaly
02:47
created

Condition   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 6
Bugs 0 Features 2
Metric Value
wmc 6
c 6
b 0
f 2
lcom 1
cbo 1
dl 0
loc 60
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addArgument() 0 7 1
A addCondition() 0 7 1
A add() 0 9 2
A __construct() 0 4 2
1
<?php
2
namespace samsonframework\orm;
3
4
use samsonframework\orm\ConditionInterface;
5
use samsonframework\orm\ArgumentInterface;
6
7
/**
8
 * Query condition arguments group
9
 * @author Vitaly Iegorov <[email protected]>
10
 * @version 2.0
11
 */
12
class Condition implements ConditionInterface
13
{
14
    /** @var Argument[] Collection of condition arguments */
15
    public $arguments = array();
16
17
    /** @var string Relation logic between arguments */
18
    public $relation = ConditionInterface::CONJUNCTION;
19
20
    /**
21
     * Add condition argument to this condition group
22
     * @param ArgumentInterface $argument Condition argument to be added
23
     * @return self Chaining
24
     */
25
    public function addArgument(ArgumentInterface $argument)
26
    {
27
        // Add condition as current condition argument
28
        $this->arguments[] = $argument;
29
30
        return $this;
31
    }
32
33
    /**
34
     * Add condition group to this condition group
35
     * @param self $condition Condition group to be added
36
     * @return self Chaining
37
     */
38
    public function addCondition(ConditionInterface $condition)
39
    {
40
        // Add condition as current condition argument
41
        $this->arguments[] = $condition;
42
43
        return $this;
44
    }
45
46
    /**
47
     * Generic condition addiction function
48
     * @param string $argument Entity for adding to arguments collection
49
     * @param mixed $value Argument value
50
     * @param string $relation Relation between argument and value
51
     * @return self Chaining
52
     */
53
    public function add($argument, $value, $relation = ArgumentInterface::EQUAL)
54
    {
55
        if (is_string($argument)) {
56
            // Add new argument to arguments collection
57
            $this->arguments[] = new Argument($argument, $value, $relation);
58
        }
59
60
        return $this;
61
    }
62
63
    /**
64
     * Constructor
65
     * @param string $relation Relation type between arguments
66
     */
67
    public function __construct($relation = null)
68
    {
69
        $this->relation = isset($relation) ? $relation : ConditionInterface::CONJUNCTION;
70
    }
71
}
72