Completed
Push — master ( 1e376d...b0060a )
by Changwan
05:50
created

DropQuery::toSql()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 10
nc 8
nop 0
dl 0
loc 15
ccs 13
cts 13
cp 1
crap 6
rs 8.8571
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Database\Query;
3
4
use Wandu\Database\Contracts\QueryInterface;
5
use Wandu\Database\Support\Attributes;
6
7
/**
8
 * @see http://dev.mysql.com/doc/refman/5.7/en/drop-table.html
9
 *
10
 * DROP TABLE [IF EXISTS] tbl_name [RESTRICT | CASCADE]
11
 *
12
 * @method \Wandu\Database\Query\DropQuery ifExists()
13
 * @method \Wandu\Database\Query\DropQuery restrict()
14
 * @method \Wandu\Database\Query\DropQuery cascade()
15
 */
16
class DropQuery implements QueryInterface
17
{
18
    use Attributes;
19
20
    /** @var string */
21
    protected $table;
22
23
    /**
24
     * @param string $table
25
     */
26 1
    public function __construct($table)
27
    {
28 1
        $this->table = $table;
29 1
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 1
    public function toSql()
35
    {
36 1
        $sql = "DROP TABLE";
37 1
        if (isset($this->attributes['if_exists'])) {
38 1
            $sql .= ' IF EXISTS';
39 1
        }
40 1
        $sql .= " `{$this->table}`";
41 1
        if (isset($this->attributes['restrict']) && $this->attributes['restrict']) {
42 1
            $sql .= ' RESTRICT';
43 1
        }
44 1
        if (isset($this->attributes['cascade']) && $this->attributes['cascade']) {
45 1
            $sql .= ' CASCADE';
46 1
        }
47 1
        return $sql;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getBindings()
54
    {
55
        return [];
56
    }
57
}
58