Passed
Pull Request — 2.1 (#71)
by Vincent
13:18 queued 06:40
created

SimpleWhereTrait::orWhereNull()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Bdf\Prime\Query\Extension;
4
5
use Bdf\Prime\Query\Clause;
6
use Bdf\Prime\Query\Compiler\CompilerState;
7
use Bdf\Prime\Query\Contract\Whereable;
8
use Doctrine\DBAL\Query\Expression\CompositeExpression;
9
10
/**
11
 * Trait for where() method
12
 *
13
 * @see Whereable
14
 * @property CompilerState $compilerState
15
 *
16
 * @psalm-require-implements Whereable
17
 */
18
trait SimpleWhereTrait
19
{
20
    /**
21
     * {@inheritdoc}
22
     *
23
     * @see Whereable::where()
24
     */
25 663
    public function where($column, $operator = null, $value = null)
26
    {
27 663
        if (!is_string($column) && is_callable($column)) {
28 9
            $this->nested($column, $operator ?: CompositeExpression::TYPE_AND);
29
        } else {
30 663
            $this->compilerState->invalidate('where');
31
32 663
            $this->buildClause('where', $column, $operator, $value);
33
        }
34
35 663
        return $this;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     *
41
     * @see Whereable::orWhere()
42
     */
43 13
    public function orWhere($column, $operator = null, $value = null)
44
    {
45 13
        if (!is_string($column) && is_callable($column)) {
46 1
            $this->nested($column, $operator ?: CompositeExpression::TYPE_OR);
47
        } else {
48 13
            $this->compilerState->invalidate('where');
49
50 13
            $this->buildClause('where', $column, $operator, $value, CompositeExpression::TYPE_OR);
51
        }
52
53 13
        return $this;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     *
59
     * @see Whereable::whereNull()
60
     */
61 2
    public function whereNull(string $column, string $type = CompositeExpression::TYPE_AND)
62
    {
63 2
        $this->compilerState->invalidate('where');
64
65 2
        return $this->buildClause('where', $column, '=', null, $type);
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     *
71
     * @see Whereable::whereNotNull()
72
     */
73 2
    public function whereNotNull(string $column, string $type = CompositeExpression::TYPE_AND)
74
    {
75 2
        $this->compilerState->invalidate('where');
76
77 2
        return $this->buildClause('where', $column, '!=', null, $type);
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     *
83
     * @see Whereable::orWhereNull()
84
     */
85 1
    public function orWhereNull(string $column)
86
    {
87 1
        return $this->whereNull($column, CompositeExpression::TYPE_OR);
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     *
93
     * @see Whereable::orWhereNotNull()
94
     */
95 1
    public function orWhereNotNull(string $column)
96
    {
97 1
        return $this->whereNotNull($column, CompositeExpression::TYPE_OR);
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     *
103
     * @see Whereable::whereRaw()
104
     */
105 6
    public function whereRaw($raw, string $type = CompositeExpression::TYPE_AND)
106
    {
107 6
        $this->compilerState->invalidate('where');
108
109 6
        return $this->buildRaw('where', $raw, $type);
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     *
115
     * @see Whereable::orWhereRaw()
116
     */
117 2
    public function orWhereRaw($raw)
118
    {
119 2
        return $this->whereRaw($raw, CompositeExpression::TYPE_OR);
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     *
125
     * @see Whereable::nested()
126
     */
127 10
    public function nested(callable $callback, string $type = CompositeExpression::TYPE_AND)
128
    {
129 10
        $this->compilerState->invalidate('where');
130
131 10
        return $this->buildNested('where', $callback, $type);
132
    }
133
134
    /**
135
     * {@inheritdoc}
136
     *
137
     * @see Clause::buildClause()
138
     */
139
    abstract public function buildClause(string $statement, $expression, $operator = null, $value = null, string $type = CompositeExpression::TYPE_AND);
140
141
    /**
142
     * {@inheritdoc}
143
     *
144
     * @see Clause::buildNested()
145
     */
146
    abstract public function buildNested(string $statement, callable $callback, string $type = CompositeExpression::TYPE_AND);
147
148
    /**
149
     * {@inheritdoc}
150
     *
151
     * @see Clause::buildRaw()
152
     */
153
    abstract public function buildRaw(string $statement, $expression, string $type = CompositeExpression::TYPE_AND);
154
}
155