Passed
Branch dev (ea35c5)
by Wilmer
17:29 queued 12:43
created

DDLQueryBuilder::truncateTable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Sqlite;
6
7
use Yiisoft\Db\Exception\Exception;
8
use Yiisoft\Db\Exception\InvalidArgumentException;
9
use Yiisoft\Db\Exception\NotSupportedException;
10
use Yiisoft\Db\Query\DDLQueryBuilder as AbstractDDLQueryBuilder;
11
use Yiisoft\Db\Query\QueryBuilderInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Db\Query\QueryBuilderInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
final class DDLQueryBuilder extends AbstractDDLQueryBuilder
14
{
15 323
    public function __construct(private QueryBuilderInterface $queryBuilder)
16
    {
17 323
        parent::__construct($queryBuilder);
18
    }
19
20
    /**
21
     * @throws NotSupportedException
22
     */
23
    public function addCheck(string $name, string $table, string $expression): string
24
    {
25
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
26
    }
27
28
    /**
29
     * @throws NotSupportedException
30
     */
31
    public function addCommentOnColumn(string $table, string $column, string $comment): string
32
    {
33
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
34
    }
35
36
    /**
37
     * @throws NotSupportedException
38
     */
39
    public function addCommentOnTable(string $table, string $comment): string
40
    {
41
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
42
    }
43
44
    /**
45
     * @throws NotSupportedException
46
     */
47 3
    public function addForeignKey(
48
        string $name,
49
        string $table,
50
        array|string $columns,
51
        string $refTable,
52
        array|string $refColumns,
53
        ?string $delete = null,
54
        ?string $update = null
55
    ): string {
56 3
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
57
    }
58
59
    /**
60
     * @throws NotSupportedException
61
     */
62
    public function addPrimaryKey(string $name, string $table, array|string $columns): string
63
    {
64
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
65
    }
66
67
    /**
68
     * @throws NotSupportedException
69
     */
70 1
    public function addUnique(string $name, string $table, array|string $columns): string
71
    {
72 1
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
73
    }
74
75
    /**
76
     * @throws NotSupportedException
77
     */
78
    public function alterColumn(string $table, string $column, string $type): string
79
    {
80
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
81
    }
82
83
    public function checkIntegrity(string $schema = '', string $table = '', bool $check = true): string
84
    {
85
        return 'PRAGMA foreign_keys=' . (int) $check;
86
    }
87
88
    /**
89
     * @throws Exception|InvalidArgumentException
90
     */
91 7
    public function createIndex(string $name, string $table, array|string $columns, bool $unique = false): string
92
    {
93 7
        $tableParts = explode('.', $table);
94
95 7
        $schema = null;
96 7
        if (count($tableParts) === 2) {
97 1
            [$schema, $table] = $tableParts;
98
        }
99
100 7
        return ($unique ? 'CREATE UNIQUE INDEX ' : 'CREATE INDEX ')
101 7
            . $this->queryBuilder->quoter()->quoteTableName(($schema ? $schema . '.' : '') . $name)
102
            . ' ON '
103 7
            . $this->queryBuilder->quoter()->quoteTableName($table)
104 7
            . ' (' . $this->queryBuilder->buildColumns($columns) . ')';
105
    }
106
107
    /**
108
     * @throws NotSupportedException
109
     */
110
    public function dropCheck(string $name, string $table): string
111
    {
112
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
113
    }
114
115
    /**
116
     * @throws NotSupportedException
117
     */
118
    public function dropColumn(string $table, string $column): string
119
    {
120
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
121
    }
122
123
    /**
124
     * @throws NotSupportedException
125
     */
126
    public function dropCommentFromColumn(string $table, string $column): string
127
    {
128
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
129
    }
130
131
    /**
132
     * @throws NotSupportedException
133
     */
134
    public function dropCommentFromTable(string $table): string
135
    {
136
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
137
    }
138
139
    /**
140
     * @throws NotSupportedException
141
     */
142 2
    public function dropForeignKey(string $name, string $table): string
143
    {
144 2
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
145
    }
146
147 2
    public function dropIndex(string $name, string $table): string
148
    {
149 2
        return 'DROP INDEX ' . $this->queryBuilder->quoter()->quoteTableName($name);
150
    }
151
152
    /**
153
     * @throws NotSupportedException
154
     */
155
    public function dropPrimaryKey(string $name, string $table): string
156
    {
157
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
158
    }
159
160
    /**
161
     * @throws NotSupportedException
162
     */
163 1
    public function dropUnique(string $name, string $table): string
164
    {
165 1
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
166
    }
167
168
    /**
169
     * @throws NotSupportedException
170
     */
171
    public function renameColumn(string $table, string $oldName, string $newName): string
172
    {
173
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
174
    }
175
176 3
    public function renameTable(string $oldName, string $newName): string
177
    {
178
        return 'ALTER TABLE '
179 3
            . $this->queryBuilder->quoter()->quoteTableName($oldName)
180
            . ' RENAME TO '
181 3
            . $this->queryBuilder->quoter()->quoteTableName($newName);
182
    }
183
184 1
    public function truncateTable(string $table): string
185
    {
186 1
        return 'DELETE FROM ' . $this->queryBuilder->quoter()->quoteTableName($table);
187
    }
188
}
189