Completed
Pull Request — 2.x (#99)
by Hari
07:29 queued 05:28
created

Delete::from()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.037

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 2
cts 3
cp 0.6667
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1.037
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
use Aura\SqlQuery\AbstractDmlQuery;
12
13
/**
14
 *
15
 * An object for DELETE queries.
16
 *
17
 * @package Aura.SqlQuery
18
 *
19
 */
20
class Delete extends AbstractDmlQuery implements DeleteInterface
21
{
22
    /**
23
     *
24
     * The table to delete from.
25
     *
26
     * @var string
27
     *
28
     */
29
    protected $from;
30
31
    /**
32
     *
33
     * Sets the table to delete from.
34
     *
35
     * @param string $table The table to delete from.
36
     *
37
     * @return $this
38
     *
39
     */
40 13
    public function from($table)
41
    {
42
        $this->from = $this->quoter->quoteName($table);
43 13
        return $this;
44
    }
45
46
    /**
47
     *
48
     * Builds this query object into a string.
49
     *
50
     * @return string
51
     *
52
     */
53 11
    protected function build()
54
    {
55 11
        return 'DELETE'
56
            . $this->buildFlags()
57
            . $this->buildFrom()
58
            . $this->buildWhere()
59
            . $this->buildOrderBy()
60
            . $this->buildLimit()
61
            . $this->buildReturning();
62
    }
63
64
    /**
65
     *
66
     * Builds the FROM clause.
67
     *
68
     * @return string
69
     *
70
     */
71 11
    protected function buildFrom()
72
    {
73 11
        return " FROM {$this->from}";
74
    }
75
76
    /**
77
     *
78
     * Adds a WHERE condition to the query by AND. If the condition has
79
     * ?-placeholders, additional arguments to the method will be bound to
80
     * those placeholders sequentially.
81
     *
82
     * @param string $cond The WHERE condition.
83
     * @param mixed ...$bind arguments to bind to placeholders
84
     *
85
     * @return $this
86
     *
87
     */
88
    public function where($cond)
89
    {
90
        $this->addWhere('AND', func_get_args());
91
        return $this;
92
    }
93
94
    /**
95
     *
96
     * Adds a WHERE condition to the query by OR. If the condition has
97
     * ?-placeholders, additional arguments to the method will be bound to
98
     * those placeholders sequentially.
99
     *
100
     * @param string $cond The WHERE condition.
101
     * @param mixed ...$bind arguments to bind to placeholders
102
     *
103
     * @return $this
104
     *
105
     * @see where()
106
     *
107
     */
108 10
    public function orWhere($cond)
109
    {
110
        $this->addWhere('OR', func_get_args());
111 10
        return $this;
112
    }
113
}
114