Completed
Pull Request — 3.x (#116)
by
unknown
01:52
created

Delete::orWhere()   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
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
    use WhereTrait;
23
24
    /**
25
     *
26
     * The table to delete from.
27
     *
28
     * @var string
29
     *
30
     */
31
    protected $from;
32
33
    /**
34
     *
35
     * Sets the table to delete from.
36
     *
37
     * @param string $table The table to delete from.
38
     *
39
     * @return $this
40
     *
41
     */
42 13
    public function from($table)
43
    {
44 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...
45 13
        return $this;
46
    }
47
48
    /**
49
     *
50
     * Builds this query object into a string.
51
     *
52
     * @return string
53
     *
54
     */
55 11
    protected function build()
56
    {
57
        return 'DELETE'
58 11
            . $this->buildFlags()
59 11
            . $this->buildFrom()
60 11
            . $this->buildWhere()
61 11
            . $this->buildOrderBy()
62 11
            . $this->buildLimit()
63 11
            . $this->buildReturning();
64
    }
65
66
    /**
67
     *
68
     * Builds the FROM clause.
69
     *
70
     * @return string
71
     *
72
     */
73 11
    protected function buildFrom()
74
    {
75 11
        return " FROM {$this->from}";
76
    }
77
}
78