Q   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 68
rs 10
c 0
b 0
f 0
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A addWhere() 0 4 1
A getWhere() 0 3 1
A getOperator() 0 3 1
A __construct() 0 3 1
A parseConditions() 0 7 2
A parsePart() 0 7 2
A toSQL() 0 3 1
1
<?php
2
3
namespace Tsukasa\QueryBuilder\Q;
4
5
use Tsukasa\QueryBuilder\Expression\AbstractExpression;
6
7
abstract class Q extends AbstractExpression
8
{
9
    /**
10
     * @var array|string|Q
11
     */
12
    protected $where;
13
    /**
14
     * @var string
15
     */
16
    protected $operator = 'AND';
17
18
    public function __construct($where)
19
    {
20
        $this->where = $where;
21
    }
22
23
    public function getWhere()
24
    {
25
        return $this->where;
26
    }
27
28
    public function addWhere($where)
29
    {
30
        $this->where[] = $where;
31
        return $this;
32
    }
33
34
    /**
35
     * @return string
36
     */
37
    public function getOperator()
38
    {
39
        return $this->operator;
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function toSQL()
46
    {
47
        return $this->parseConditions($this->where);
48
    }
49
50
    /**
51
     * @param array $where
52
     * @return string
53
     */
54
    protected function parseConditions($where)
55
    {
56
        if (empty($where)) {
57
            return '';
58
        }
59
60
        return $this->qb->parseCondition($where, $this->getOperator());
61
    }
62
63
    /**
64
     * @param $part
65
     * @param null|string $operator
66
     * @return string
67
     */
68
    protected function parsePart($part, $operator = null)
69
    {
70
        if ($operator === null) {
71
            $operator = $this->getOperator();
72
        }
73
74
        return $this->qb->parseCondition($part, $operator);
75
    }
76
}