Completed
Push — 3.x ( f5caca...8b4f6e )
by Hari
01:48
created

WhereTrait::where()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 *
8
 */
9
namespace Aura\SqlQuery\Common;
10
11
/**
12
 *
13
 * Common code for WHERE clauses.
14
 *
15
 * @package Aura.SqlQuery
16
 *
17
 */
18
trait WhereTrait
19
{
20
    /**
21
     *
22
     * Adds a WHERE condition to the query by AND. If the condition has
23
     * ?-placeholders, additional arguments to the method will be bound to
24
     * those placeholders sequentially.
25
     *
26
     * @param string $cond The WHERE condition.
27
     * @param mixed ...$bind arguments to be bound to placeholders
28
     *
29
     * @return $this
30
     *
31
     */
32 55
    public function where($cond, ...$bind)
33
    {
34 55
        $this->addWhere('AND', $cond, ...$bind);
35 55
        return $this;
36
    }
37
38
    /**
39
     *
40
     * Adds a WHERE condition to the query by OR. If the condition has
41
     * ?-placeholders, additional arguments to the method will be bound to
42
     * those placeholders sequentially.
43
     *
44
     * @param string $cond The WHERE condition.
45
     * @param mixed ...$bind arguments to be bound to placeholders
46
     *
47
     * @return $this
48
     *
49
     * @see where()
50
     *
51
     */
52 29
    public function orWhere($cond, ...$bind)
53
    {
54 29
        $this->addWhere('OR', $cond, ...$bind);
55 29
        return $this;
56
    }
57
58
    /**
59
     *
60
     * Adds a WHERE condition to the query by AND or OR. If the condition has
61
     * ?-placeholders, additional arguments to the method will be bound to
62
     * those placeholders sequentially.
63
     *
64
     * @param string $andor Add the condition using this operator, typically
65
     * 'AND' or 'OR'.
66
     * @param string $cond The WHERE condition.
67
     * @param mixed ...$bind arguments to bind to placeholders
68
     *
69
     * @return $this
70
     *
71
     */
72
    abstract protected function addWhere($andor, $cond, ...$bind);
73
}
74