Test Failed
Pull Request — dev (#92)
by Def
02:44
created

QueryBuilderPDOMssql::renameTable()   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
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql\PDO;
6
7
use Yiisoft\Db\Mssql\DDLQueryBuilder;
8
use Yiisoft\Db\Mssql\DMLQueryBuilder;
9
use Yiisoft\Db\Mssql\DQLQueryBuilder;
10
use Yiisoft\Db\Query\QueryBuilder;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Db\Query\QueryBuilder 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
use Yiisoft\Db\Schema\ColumnSchemaBuilder;
12
use Yiisoft\Db\Schema\QuoterInterface;
13
use Yiisoft\Db\Schema\Schema;
14
use Yiisoft\Db\Schema\SchemaInterface;
15
16
use function preg_replace;
17
18
final class QueryBuilderPDOMssql extends QueryBuilder
19
{
20
    /**
21
     * @psalm-var string[] $typeMap Mapping from abstract column types (keys) to physical column types (values).
22
     */
23
    protected array $typeMap = [
24
        Schema::TYPE_PK => 'int IDENTITY PRIMARY KEY',
25
        Schema::TYPE_UPK => 'int IDENTITY PRIMARY KEY',
26
        Schema::TYPE_BIGPK => 'bigint IDENTITY PRIMARY KEY',
27
        Schema::TYPE_UBIGPK => 'bigint IDENTITY PRIMARY KEY',
28
        Schema::TYPE_CHAR => 'nchar(1)',
29
        Schema::TYPE_STRING => 'nvarchar(255)',
30
        Schema::TYPE_TEXT => 'nvarchar(max)',
31
        Schema::TYPE_TINYINT => 'tinyint',
32
        Schema::TYPE_SMALLINT => 'smallint',
33
        Schema::TYPE_INTEGER => 'int',
34
        Schema::TYPE_BIGINT => 'bigint',
35
        Schema::TYPE_FLOAT => 'float',
36
        Schema::TYPE_DOUBLE => 'float',
37
        Schema::TYPE_DECIMAL => 'decimal(18,0)',
38
        Schema::TYPE_DATETIME => 'datetime',
39
        Schema::TYPE_TIMESTAMP => 'datetime',
40
        Schema::TYPE_TIME => 'time',
41
        Schema::TYPE_DATE => 'date',
42
        Schema::TYPE_BINARY => 'varbinary(max)',
43
        Schema::TYPE_BOOLEAN => 'bit',
44
        Schema::TYPE_MONEY => 'decimal(19,4)',
45
    ];
46
    private DDLQueryBuilder $ddlBuilder;
47
    private DMLQueryBuilder $dmlBuilder;
48
    private DQLQueryBuilder $dqlBuilder;
49
50
    public function __construct(
51
        protected QuoterInterface $quoter,
52
        protected SchemaInterface $schema
53
    ) {
54
        $this->ddlBuilder = new DDLQueryBuilder($this);
55
        $this->dmlBuilder = new DMLQueryBuilder($this);
56
        $this->dqlBuilder = new DQLQueryBuilder($this);
57
        parent::__construct($quoter, $schema, $this->ddlBuilder, $this->dmlBuilder, $this->dqlBuilder);
58
    }
59
60
    public function getColumnType(ColumnSchemaBuilder|string $type): string
61
    {
62 385
        $columnType = parent::getColumnType($type);
63
64
        /** remove unsupported keywords*/
65
        $columnType = preg_replace("/\s*comment '.*'/i", '', $columnType);
66
        return preg_replace('/ first$/i', '', $columnType);
67 385
    }
68
}
69