Test Failed
Pull Request — master (#82)
by Wilmer
24:21 queued 13:10
created

DDLQueryBuilder   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 24
eloc 33
dl 0
loc 126
rs 10
c 1
b 0
f 0

21 Methods

Rating   Name   Duplication   Size   Complexity  
A dropForeignKey() 0 3 1
A checkIntegrity() 0 3 1
A dropColumn() 0 3 1
A dropCommentFromTable() 0 3 1
A dropCheck() 0 3 1
A addPrimaryKey() 0 3 1
A dropCommentFromColumn() 0 3 1
A addCheck() 0 3 1
A __construct() 0 3 1
A addCommentOnTable() 0 3 1
A renameTable() 0 6 1
A addForeignKey() 0 10 1
A truncateTable() 0 3 1
A addUnique() 0 3 1
A dropPrimaryKey() 0 3 1
A renameColumn() 0 3 1
A createIndex() 0 14 4
A alterColumn() 0 3 1
A addCommentOnColumn() 0 3 1
A dropUnique() 0 3 1
A dropIndex() 0 3 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\NotSupportedException;
9
use Yiisoft\Db\Query\DDLQueryBuilder as AbstractDDLQueryBuilder;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Db\Query\DDLQueryBuilder 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...
10
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...
11
12
final class DDLQueryBuilder extends AbstractDDLQueryBuilder
13
{
14
    public function __construct(private QueryBuilderInterface $queryBuilder)
15
    {
16
        parent::__construct($queryBuilder);
17
    }
18
19
    public function addCheck(string $name, string $table, string $expression): string
20
    {
21
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
22
    }
23
24
    public function addCommentOnColumn(string $table, string $column, string $comment): string
25
    {
26
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
27
    }
28
29
    public function addCommentOnTable(string $table, string $comment): string
30
    {
31
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
32
    }
33
34
    public function addForeignKey(
35
        string $name,
36
        string $table,
37
        array|string $columns,
38
        string $refTable,
39
        array|string $refColumns,
40
        ?string $delete = null,
41
        ?string $update = null
42
    ): string {
43
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
44
    }
45
46
    public function addPrimaryKey(string $name, string $table, array|string $columns): string
47
    {
48
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
49
    }
50
51
    public function addUnique(string $name, string $table, array|string $columns): string
52
    {
53
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
54
    }
55
56
    public function alterColumn(string $table, string $column, string $type): string
57
    {
58
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
59
    }
60
61
    public function checkIntegrity(string $schema = '', string $table = '', bool $check = true): string
62
    {
63
        return 'PRAGMA foreign_keys=' . (int) $check;
64
    }
65
66
    public function createIndex(string $name, string $table, array|string $columns, bool $unique = false): string
67
    {
68
        $tableParts = explode('.', $table);
69
70
        $schema = null;
71
        if (count($tableParts) === 2) {
72
            [$schema, $table] = $tableParts;
73
        }
74
75
        return ($unique ? 'CREATE UNIQUE INDEX ' : 'CREATE INDEX ')
76
            . $this->queryBuilder->quoter()->quoteTableName(($schema ? $schema . '.' : '') . $name)
77
            . ' ON '
78
            . $this->queryBuilder->quoter()->quoteTableName($table)
79
            . ' (' . $this->queryBuilder->buildColumns($columns) . ')';
80
    }
81
82
    public function dropCheck(string $name, string $table): string
83
    {
84
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
85
    }
86
87
    public function dropColumn(string $table, string $column): string
88
    {
89
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
90
    }
91
92
    public function dropCommentFromColumn(string $table, string $column): string
93
    {
94
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
95
    }
96
97
    public function dropCommentFromTable(string $table): string
98
    {
99
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
100
    }
101
102
    public function dropForeignKey(string $name, string $table): string
103
    {
104
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
105
    }
106
107
    public function dropIndex(string $name, string $table): string
108
    {
109
        return 'DROP INDEX ' . $this->queryBuilder->quoter()->quoteTableName($name);
110
    }
111
112
    public function dropPrimaryKey(string $name, string $table): string
113
    {
114
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
115
    }
116
117
    public function dropUnique(string $name, string $table): string
118
    {
119
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
120
    }
121
122
    public function renameColumn(string $table, string $oldName, string $newName): string
123
    {
124
        throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
125
    }
126
127
    public function renameTable(string $oldName, string $newName): string
128
    {
129
        return 'ALTER TABLE '
130
            . $this->queryBuilder->quoter()->quoteTableName($oldName)
131
            . ' RENAME TO '
132
            . $this->queryBuilder->quoter()->quoteTableName($newName);
133
    }
134
135
    public function truncateTable(string $table): string
136
    {
137
        return 'DELETE FROM ' . $this->queryBuilder->quoter()->quoteTableName($table);
138
    }
139
}
140