Completed
Push — master ( 360009...4a8242 )
by Beniamin
04:49
created

ComparisionTrait::conjunction()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
ccs 0
cts 0
cp 0
nc 1
1
<?php
2
3
/**
4
 * This file is part of Phuria SQL Builder package.
5
 *
6
 * Copyright (c) 2016 Beniamin Jonatan Šimko
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phuria\QueryBuilder\ExprBuilder;
13
14
use Phuria\QueryBuilder\ExprBuilder;
15
use Phuria\QueryBuilder\Expression\Comparison\Between;
16
use Phuria\QueryBuilder\Expression\Comparison\IsNull;
17
use Phuria\QueryBuilder\Expression\Comparison\NotBetween;
18
use Phuria\QueryBuilder\Expression\ConjunctionExpression;
19
use Phuria\QueryBuilder\Expression\ExpressionInterface;
20
use Phuria\QueryBuilder\ExprNormalizer;
21
22
/**
23
 * @author Beniamin Jonatan Šimko <[email protected]>
24
 */
25
trait ComparisionTrait
26
{
27
    /**
28
     * @param $connector
29
     * @param $expression
30
     *
31
     * @return ExprBuilder
32
     */
33
    abstract public function conjunction($connector, $expression);
34
35
    /**
36
     * @return ExpressionInterface
37
     */
38
    abstract public function getWrappedExpression();
39
40
41
    /**
42
     * @param mixed $from
43
     * @param mixed $to
44
     *
45
     * @return ExprBuilder
46
     */
47 1
    public function between($from, $to)
48
    {
49 1
        $from = ExprNormalizer::normalizeExpression($from);
50 1
        $to = ExprNormalizer::normalizeExpression($to);
51
52 1
        return new ExprBuilder(new Between($this->getWrappedExpression(), $from, $to));
53
    }
54
55
    /**
56
     * @param mixed $expression
57
     *
58
     * @return ExprBuilder
59
     */
60 1
    public function eq($expression)
61
    {
62 1
        $expression = ExprNormalizer::normalizeExpression($expression);
63
64 1
        return $this->conjunction(ConjunctionExpression::SYMBOL_EQ, $expression);
65
    }
66
67
    /**
68
     * @param mixed $expression
69
     *
70
     * @return ExprBuilder
71
     */
72 1
    public function gt($expression)
73
    {
74 1
        $expression = ExprNormalizer::normalizeExpression($expression);
75
76 1
        return $this->conjunction(ConjunctionExpression::SYMBOL_GT, $expression);
77
    }
78
79
    /**
80
     * @param mixed $expression
81
     *
82
     * @return ExprBuilder
83
     */
84
    public function gte($expression)
85
    {
86
        $expression = ExprNormalizer::normalizeExpression($expression);
87
88
        return $this->conjunction(ConjunctionExpression::SYMBOL_GTE, $expression);
89
    }
90
91
    /**
92
     * @return ExprBuilder
93
     */
94
    public function isNull()
95
    {
96
        return new ExprBuilder(new IsNull($this->getWrappedExpression()));
97
    }
98
99
    /**
100
     * @param mixed $expression
101
     *
102
     * @return ExprBuilder
103
     */
104
    public function lt($expression)
105
    {
106
        $expression = ExprNormalizer::normalizeExpression($expression);
107
108
        return $this->conjunction(ConjunctionExpression::SYMBOL_LT, $expression);
109
    }
110
111
    /**
112
     * @param mixed $expression
113
     *
114
     * @return ExprBuilder
115
     */
116
    public function lte($expression)
117
    {
118
        $expression = ExprNormalizer::normalizeExpression($expression);
119
120
        return $this->conjunction(ConjunctionExpression::SYMBOL_LTE, $expression);
121
    }
122
123
    /**
124
     * @param mixed $expression
125
     *
126
     * @return ExprBuilder
127
     */
128
    public function neq($expression)
129
    {
130
        $expression = ExprNormalizer::normalizeExpression($expression);
131
132
        return $this->conjunction(ConjunctionExpression::SYMBOL_NEQ, $expression);
133
    }
134
135
    /**
136
     * @param mixed $from
137
     * @param mixed $to
138
     *
139
     * @return ExprBuilder
140
     */
141 1
    public function notBetween($from, $to)
142
    {
143 1
        $from = ExprNormalizer::normalizeExpression($from);
144 1
        $to = ExprNormalizer::normalizeExpression($to);
145
146 1
        return new ExprBuilder(new NotBetween($this->getWrappedExpression(), $from, $to));
147
    }
148
149
    /**
150
     * @param mixed $expression
151
     *
152
     * @return ExprBuilder
153
     */
154
    public function nullEq($expression)
155
    {
156
        $expression = ExprNormalizer::normalizeExpression($expression);
157
158
        return $this->conjunction(ConjunctionExpression::SYMBOL_NULL_EQ, $expression);
159
    }
160
}