Completed
Push — 2.x ( dd81b5...f59f8a )
by Paul
8s
created

Delete   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 94
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A from() 0 5 1
A build() 0 10 1
A buildFrom() 0 4 1
A where() 0 5 1
A orWhere() 0 5 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
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 13
        $this->from = $this->quoter->quoteName($table);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->quoter->quoteName($table) can also be of type array. However, the property $from is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
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
        return 'DELETE'
56 11
            . $this->buildFlags()
57 11
            . $this->buildFrom()
58 11
            . $this->buildWhere()
59 11
            . $this->buildOrderBy()
60 11
            . $this->buildLimit()
61 11
            . $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 10
    public function where($cond)
89
    {
90 10
        $this->addWhere('AND', func_get_args());
91 10
        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 10
        $this->addWhere('OR', func_get_args());
111 10
        return $this;
112
    }
113
}
114