Passed
Branch master (deb69d)
by Wilmer
14:01 queued 01:23
created

QueryBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Sqlite;
6
7
use Yiisoft\Db\QueryBuilder\QueryBuilder as AbstractQueryBuilder;
8
use Yiisoft\Db\Schema\QuoterInterface;
9
use Yiisoft\Db\Schema\Schema;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Yiisoft\Db\Sqlite\Schema. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
use Yiisoft\Db\Schema\SchemaInterface;
11
12
final class QueryBuilder extends AbstractQueryBuilder
13
{
14
    /**
15
     * @var array mapping from abstract column types (keys) to physical column types (values).
16
     *
17
     * @psalm-var string[] $typeMap
18
     */
19
    protected array $typeMap = [
20
        Schema::TYPE_PK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
21
        Schema::TYPE_UPK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
22
        Schema::TYPE_BIGPK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
23
        Schema::TYPE_UBIGPK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
24
        Schema::TYPE_CHAR => 'char(1)',
25
        Schema::TYPE_STRING => 'varchar(255)',
26
        Schema::TYPE_TEXT => 'text',
27
        Schema::TYPE_TINYINT => 'tinyint',
28
        Schema::TYPE_SMALLINT => 'smallint',
29
        Schema::TYPE_INTEGER => 'integer',
30
        Schema::TYPE_BIGINT => 'bigint',
31
        Schema::TYPE_FLOAT => 'float',
32
        Schema::TYPE_DOUBLE => 'double',
33
        Schema::TYPE_DECIMAL => 'decimal(10,0)',
34
        Schema::TYPE_DATETIME => 'datetime',
35
        Schema::TYPE_TIMESTAMP => 'timestamp',
36
        Schema::TYPE_TIME => 'time',
37
        Schema::TYPE_DATE => 'date',
38
        Schema::TYPE_BINARY => 'blob',
39
        Schema::TYPE_BOOLEAN => 'boolean',
40
        Schema::TYPE_MONEY => 'decimal(19,4)',
41
    ];
42
    private DDLQueryBuilder $ddlBuilder;
43
    private DMLQueryBuilder $dmlBuilder;
44
    private DQLQueryBuilder $dqlBuilder;
45
46 338
    public function __construct(QuoterInterface $quoter, SchemaInterface $schema)
47
    {
48 338
        $this->ddlBuilder = new DDLQueryBuilder($this, $quoter, $schema);
49 338
        $this->dmlBuilder = new DMLQueryBuilder($this, $quoter, $schema);
50 338
        $this->dqlBuilder = new DQLQueryBuilder($this, $quoter, $schema);
51 338
        parent::__construct($quoter, $schema, $this->ddlBuilder, $this->dmlBuilder, $this->dqlBuilder);
52
    }
53
}
54