Completed
Push — master ( 78fbbf...ba1e76 )
by Iqbal
02:26
created

PdoExpression::isNull()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/*
3
 * This file is part of the Borobudur-Cqrs package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Borobudur\Cqrs\ReadModel\Storage\Pdo\Expression;
12
13
use Borobudur\Cqrs\ReadModel\Storage\Finder\Expression\CompositeExpressionInterface;
14
use Borobudur\Cqrs\ReadModel\Storage\Finder\Expression\ExpressionInterface;
15
use Borobudur\Cqrs\ReadModel\Storage\Pdo\Parser\ParserInterface;
16
17
/**
18
 * @author      Iqbal Maulana <[email protected]>
19
 * @created     8/18/15
20
 */
21
class PdoExpression implements ExpressionInterface
22
{
23
    /**
24
     * @var ParserInterface
25
     */
26
    private $parser;
27
28
    /**
29
     * Constructor.
30
     *
31
     * @param ParserInterface $parser
32
     */
33
    public function __construct(ParserInterface $parser)
34
    {
35
        $this->parser = $parser;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function logicalAnd($expr, $_ = null)
42
    {
43
        return new PdoCompositeExpression(CompositeExpressionInterface::LOGICAL_AND, func_get_args());
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function logicalOr($expr, $_ = null)
50
    {
51
        return new PdoCompositeExpression(CompositeExpressionInterface::LOGICAL_OR, func_get_args());
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function isNull($field)
58
    {
59
        return $this->parser->comparison($field, 'IS', null);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function isNotNull($field)
66
    {
67
        return $this->parser->comparison($field, 'IS NOT', null);
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function equal($field, $value)
74
    {
75
        return $this->parser->comparison($field, '=', $value);
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function notEqual($field, $value)
82
    {
83
        return $this->parser->comparison($field, '<>', $value);
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function lessThan($field, $value)
90
    {
91
        return $this->parser->comparison($field, '<', $value);
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function lessThanEqual($field, $value)
98
    {
99
        return $this->parser->comparison($field, '<=', $value);
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function greaterThan($field, $value)
106
    {
107
        return $this->parser->comparison($field, '>', $value);
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113
    public function greaterThanEqual($field, $value)
114
    {
115
        return $this->parser->comparison($field, '>=', $value);
116
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121
    public function like($field, $value)
122
    {
123
        return $this->parser->comparison($field, 'LIKE', $value);
124
    }
125
126
    /**
127
     * {@inheritdoc}
128
     */
129
    public function notLike($field, $value)
130
    {
131
        return $this->parser->comparison($field, 'NOT LIKE', $value);
132
    }
133
134
    /**
135
     * {@inheritdoc}
136
     */
137
    public function in($field, $value)
138
    {
139
        return $this->parser->comparison($field, 'IN', $this->parser->normalizeGroupValue($value));
140
    }
141
142
    /**
143
     * {@inheritdoc}
144
     */
145
    public function notIn($field, $value)
146
    {
147
        return $this->parser->comparison($field, 'NOT IN', $this->parser->normalizeGroupValue($value));
148
    }
149
150
    /**
151
     * {@inheritdoc}
152
     */
153
    public function exists($field, $value)
154
    {
155
        return $this->parser->comparison($field, 'EXISTS', $this->parser->normalizeGroupValue($value));
156
    }
157
158
    /**
159
     * {@inheritdoc}
160
     */
161
    public function notExists($field, $value)
162
    {
163
        return $this->parser->comparison($field, 'NOT EXISTS', $this->parser->normalizeGroupValue($value));
164
    }
165
}
166