Completed
Push — master ( 1df772...b9b041 )
by Woody
12:28 queued 09:14
created

QueryFactory::insertMultiple()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Latitude\QueryBuilder;
5
6
class QueryFactory
7
{
8
    const ENGINES = [
9
        'mysql' => 'MySQL',
10
        'pgsql' => 'Postgres',
11
        'sqlsrv' => 'SqlServer',
12
    ];
13
14 6
    public function __construct(string $engine = null, bool $setIdentifier = true)
15
    {
16 6
        if ($engine && \array_key_exists($engine, static::ENGINES)) {
17 4
            $this->engine = static::ENGINES[$engine];
18
        } else {
19 2
            $this->engine = 'Common';
20
        }
21
22 6
        if ($setIdentifier) {
23 5
            $this->setDefaultIdentifier();
24
        }
25 6
    }
26
27
    /**
28
     * Create a new SELECT query.
29
     */
30 5
    public function select(...$params): SelectQuery
31
    {
32 5
        return SelectQuery::make(...$params);
33
    }
34
35
    /**
36
     * Create a new INSERT query.
37
     */
38 5
    public function insert(...$params): InsertQuery
39
    {
40 5
        if ($this->isPostgres()) {
41 1
            return Postgres\InsertQuery::make(...$params);
0 ignored issues
show
Bug introduced by Woody Gilk
The call to make() misses a required argument $map.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by Woody Gilk
$params is of type array<integer,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
42
        }
43
44 4
        return InsertQuery::make(...$params);
0 ignored issues
show
Bug introduced by Woody Gilk
The call to make() misses a required argument $map.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by Woody Gilk
$params is of type array<integer,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
    }
46
47
    /**
48
     * Create a new INSERT query with multiple values.
49
     */
50 5
    public function insertMultiple(...$params): InsertMultipleQuery
51
    {
52 5
        return InsertMultipleQuery::make(...$params);
0 ignored issues
show
Documentation introduced by Woody Gilk
$params is of type array<integer,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
53
    }
54
55
    /**
56
     * Create a new UPDATE query.
57
     */
58 5
    public function update(...$params): UpdateQuery
59
    {
60 5
        if ($this->isPostgres()) {
61 1
            return Postgres\UpdateQuery::make(...$params);
0 ignored issues
show
Bug introduced by Woody Gilk
The call to make() misses a required argument $map.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by Woody Gilk
$params is of type array<integer,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
62
        }
63
64 4
        return UpdateQuery::make(...$params);
0 ignored issues
show
Bug introduced by Woody Gilk
The call to make() misses a required argument $map.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by Woody Gilk
$params is of type array<integer,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
65
    }
66
67
    /**
68
     * Create a new DELETE query.
69
     */
70 5
    public function delete(...$params): DeleteQuery
71
    {
72 5
        if ($this->isPostgres()) {
73 1
            return Postgres\DeleteQuery::make(...$params);
0 ignored issues
show
Documentation introduced by Woody Gilk
$params is of type array<integer,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
74
        }
75
76 4
        return DeleteQuery::make(...$params);
0 ignored issues
show
Documentation introduced by Woody Gilk
$params is of type array<integer,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
77
    }
78
79
    /**
80
     * Create an identifier instance.
81
     */
82 5
    public function identifier(): Identifier
83
    {
84 5
        if ($this->isMySQL()) {
85 1
            return MySQL\Identifier::make();
86
        }
87
88 4
        if ($this->isSqlServer()) {
89 1
            return SqlServer\Identifier::make();
90
        }
91
92 3
        return Common\Identifier::make();
93
    }
94
95
    /**
96
     * Is the engine MySQL?
97
     */
98 5
    public function isMySQL(): bool
99
    {
100 5
        return $this->engine === 'MySQL';
101
    }
102
103
    /**
104
     * Is the engine Postgres?
105
     */
106 5
    public function isPostgres(): bool
107
    {
108 5
        return $this->engine === 'Postgres';
109
    }
110
111
    /**
112
     * Is the engine SQL Server?
113
     */
114 4
    public function isSqlServer(): bool
115
    {
116 4
        return $this->engine === 'SqlServer';
117
    }
118
119
    /**
120
     * @var string
121
     */
122
    protected $engine;
123
124
    /**
125
     * Set the default identifier for the engine.
126
     */
127 5
    protected function setDefaultIdentifier()
128
    {
129 5
        Identifier::setDefault($this->identifier());
130 5
    }
131
}
132