Completed
Push — master ( 07fc15...351a5c )
by Adrian
01:30
created

Where::groupCurrentWhere()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Sirius\Sql\Clause;
5
6
use Sirius\Sql\Component\Conditions;
7
8
trait Where
9
{
10
    /**
11
     * @var Conditions
12
     */
13
    protected $where;
14
15
    /**
16
     * Adds a column based condition condition
17
     *
18
     * @param string $column
19
     * @param null $value
20
     * @param string $condition
21
     *
22
     * @return $this
23
     */
24 13
    public function where(string $column, $value = null, $condition = '=')
25
    {
26 13
        if (count(func_get_args()) == 1) {
27 4
            $this->where->and($column, null, null);
28
        } else {
29 10
            $this->where->and($column, $value, $condition);
30
        }
31
32 13
        return $this;
33
    }
34
35 1
    public function whereSprintf(string $format, ...$bindInline)
36
    {
37 1
        $this->where->andSprintf($format, ...$bindInline);
38
39 1
        return $this;
40
    }
41
42 4
    public function orWhere(string $column, $value = null, $condition = '=')
43
    {
44 4
        if (count(func_get_args()) == 1) {
45 1
            $this->where->or($column, null, null);
46
        } else {
47 3
            $this->where->or($column, $value, $condition);
48
        }
49
50 4
        return $this;
51
    }
52
53 1
    public function orWhereSprintf(string $format, ...$bindInline)
54
    {
55 1
        $this->where->orSprintf($format, ...$bindInline);
56
57 1
        return $this;
58
    }
59
60 1
    public function whereAll(array $columnsValues, $isSet = true)
61
    {
62 1
        if ($isSet) {
63 1
            $this->whereStartSet();
64
        }
65
66 1
        foreach ($columnsValues as $key => $val) {
67 1
            if (is_numeric($key)) {
68 1
                $this->where($val);
69 1
            } elseif ($val === null) {
70 1
                $this->where("{$key} IS NULL");
71
            } else {
72 1
                $this->where("{$key}", $val);
73
            }
74
        }
75
76
77 1
        if ($isSet) {
78 1
            $this->endSet();
79
        }
80
81 1
        return $this;
82
    }
83
84 3
    public function whereStartSet()
85
    {
86 3
        $this->where->openGroup();
87
88 3
        return $this;
89
    }
90
91 1
    public function orWhereStartSet()
92
    {
93 1
        $this->where->openGroup('OR');
94
95 1
        return $this;
96
    }
97
98 2
    public function endSet()
99
    {
100 2
        $this->where->closeGroup();
101
102 2
        return $this;
103
104
        return $this;
0 ignored issues
show
Unused Code introduced by
return $this; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
105
    }
106
107 1
    public function groupCurrentWhere()
108
    {
109 1
        $this->where->groupCurrent();
110
111 1
        return $this;
112
    }
113
114 18
    public function resetWhere()
115
    {
116 18
        $this->where = new Conditions($this->bindings, 'WHERE');
0 ignored issues
show
Bug introduced by
The property bindings does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
117
118 18
        return $this;
119
    }
120
}
121