Test Failed
Pull Request — dev (#118)
by Def
09:16 queued 06:49
created

QueryBuilderPDOMysql::checkIntegrity()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mysql\PDO;
6
7
use Yiisoft\Db\Command\CommandInterface;
8
use Yiisoft\Db\Mysql\DDLQueryBuilder;
9
use Yiisoft\Db\Mysql\DMLQueryBuilder;
10
use Yiisoft\Db\Mysql\DQLQueryBuilder;
11
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...
12
use Yiisoft\Db\Schema\ColumnSchemaBuilder;
13
use Yiisoft\Db\Schema\QuoterInterface;
14
use Yiisoft\Db\Schema\Schema;
15
use Yiisoft\Db\Schema\SchemaInterface;
16
17
use function array_merge;
18
19
/**
20
 * The class QueryBuilder is the query builder for Mysql databases.
21
 */
22
final class QueryBuilderPDOMysql extends QueryBuilder
23
{
24
    /**
25
     * @psalm-var string[] $typeMap Mapping from abstract column types (keys) to physical column types (values).
26
     */
27
    protected array $typeMap = [
28
        Schema::TYPE_PK => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY',
29
        Schema::TYPE_UPK => 'int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY',
30
        Schema::TYPE_BIGPK => 'bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY',
31
        Schema::TYPE_UBIGPK => 'bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY',
32
        Schema::TYPE_CHAR => 'char(1)',
33
        Schema::TYPE_STRING => 'varchar(255)',
34
        Schema::TYPE_TEXT => 'text',
35
        Schema::TYPE_TINYINT => 'tinyint(3)',
36
        Schema::TYPE_SMALLINT => 'smallint(6)',
37
        Schema::TYPE_INTEGER => 'int(11)',
38
        Schema::TYPE_BIGINT => 'bigint(20)',
39
        Schema::TYPE_FLOAT => 'float',
40
        Schema::TYPE_DOUBLE => 'double',
41
        Schema::TYPE_DECIMAL => 'decimal(10,0)',
42
        Schema::TYPE_DATE => 'date',
43
        Schema::TYPE_BINARY => 'blob',
44
        Schema::TYPE_BOOLEAN => 'tinyint(1)',
45
        Schema::TYPE_MONEY => 'decimal(19,4)',
46
        Schema::TYPE_JSON => 'json',
47
    ];
48
    private DDLQueryBuilder $ddlBuilder;
49
    private DMLQueryBuilder $dmlBuilder;
50
    private DQLQueryBuilder $dqlBuilder;
51
52
    public function __construct(
53
        protected QuoterInterface $quoter,
54
        protected SchemaInterface $schema,
55
        private CommandInterface $command
56
    ) {
57
        $this->ddlBuilder = new DDLQueryBuilder($this);
58
        $this->dmlBuilder = new DMLQueryBuilder($this);
59
        $this->dqlBuilder = new DQLQueryBuilder($this);
60
        parent::__construct($quoter, $schema, $this->ddlBuilder, $this->dmlBuilder, $this->dqlBuilder);
61
    }
62
63
    public function command(): CommandInterface
64 355
    {
65
        return $this->command;
66
    }
67
68
    public function getColumnType(ColumnSchemaBuilder|string $type): string
69 355
    {
70 355
        $this->typeMap = array_merge($this->typeMap, $this->defaultTimeTypeMap());
71 355
        return parent::getColumnType($type);
72
    }
73
74
    /**
75
     * Returns the map for default time type.
76
     *
77 1
     * If the version of MySQL is lower than 5.6.4, then the types will be without fractional seconds, otherwise with
78
     * fractional seconds.
79 1
     *
80
     * @return array
81
     * @psalm-return array<string, string>
82
     */
83
    private function defaultTimeTypeMap(): array
84
    {
85 1
        return [
86
            Schema::TYPE_DATETIME => 'datetime(0)',
87 1
            Schema::TYPE_TIMESTAMP => 'timestamp(0)',
88
            Schema::TYPE_TIME => 'time(0)',
89
        ];
90
    }
91
}
92