Completed
Push — master ( ffb751...b6a1f4 )
by Jared
02:13
created

WhereConditions::where()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
rs 9.4285
cc 2
eloc 6
nc 2
nop 3
1
<?php
2
3
namespace JAQB\Query\Traits;
4
5
trait WhereConditions
6
{
7
    /**
8
     * @var WhereStatement
9
     */
10
    protected $where;
11
12
    /**
13
     * Sets the where conditions for the query.
14
     *
15
     * @param array|string $field
16
     * @param string|bool  $condition condition value (optional)
17
     * @param string       $operator  operator (optional)
18
     *
19
     * @return self
20
     */
21 View Code Duplication
    public function where($field, $condition = false, $operator = '=')
22
    {
23
        if (func_num_args() >= 2) {
24
            $this->where->addCondition($field, $condition, $operator);
25
        } else {
26
            $this->where->addCondition($field);
27
        }
28
29
        return $this;
30
    }
31
32
    /**
33
     * Adds a where or condition to the query.
34
     *
35
     * @param array|string $field
36
     * @param string       $condition condition value (optional)
37
     * @param string       $operator  operator (optional)
38
     *
39
     * @return self
40
     */
41 View Code Duplication
    public function orWhere($field, $condition = false, $operator = '=')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        if (func_num_args() >= 2) {
44
            $this->where->addConditionOr($field, $condition, $operator);
45
        } else {
46
            $this->where->addConditionOr($field);
47
        }
48
49
        return $this;
50
    }
51
52
    /**
53
     * Adds a where not condition to the query.
54
     *
55
     * @param string $field
56
     * @param string $condition condition value (optional)
57
     *
58
     * @return self
59
     */
60
    public function not($field, $condition = true)
61
    {
62
        $this->where->addCondition($field, $condition, '<>');
63
64
        return $this;
65
    }
66
67
    /**
68
     * Adds a where between condition to the query.
69
     *
70
     * @param string $field
71
     * @param mixed  $a     first between value
72
     * @param mixed  $b     second between value
73
     *
74
     * @return self
75
     */
76
    public function between($field, $a, $b)
77
    {
78
        $this->where->addBetweenCondition($field, $a, $b);
79
80
        return $this;
81
    }
82
83
    /**
84
     * Adds a where not between condition to the query.
85
     *
86
     * @param string $field
87
     * @param mixed  $a     first between value
88
     * @param mixed  $b     second between value
89
     *
90
     * @return self
91
     */
92
    public function notBetween($field, $a, $b)
93
    {
94
        $this->where->addNotBetweenCondition($field, $a, $b);
95
96
        return $this;
97
    }
98
99
    /**
100
     * Adds an exists condition to the query.
101
     *
102
     * @param callable $f
103
     *
104
     * @return self
105
     */
106
    public function exists(callable $f)
107
    {
108
        $this->where->addExistsCondition($f);
109
110
        return $this;
111
    }
112
113
    /**
114
     * Adds a not exists condition to the query.
115
     *
116
     * @param callable $f
117
     *
118
     * @return self
119
     */
120
    public function notExists(callable $f)
121
    {
122
        $this->where->addNotExistsCondition($f);
123
124
        return $this;
125
    }
126
127
    /**
128
     * Gets the where statement for the query.
129
     *
130
     * @return WhereStatement
131
     */
132
    public function getWhere()
133
    {
134
        return $this->where;
135
    }
136
}
137