Insert   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 7
dl 0
loc 46
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A into() 0 6 1
A ignore() 0 6 1
A getStatement() 0 8 1
A getLastInsertId() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Sirius\Sql;
5
6
class Insert extends Query
7
{
8
    use Clause\InsertColumns;
9
    use Clause\Returning;
10
11
    protected $table = '';
12
13
    /**
14
     * @param string $table
15
     *
16
     * @return $this
17
     */
18 1
    public function into(string $table)
19
    {
20 1
        $this->table = $table;
21
22 1
        return $this;
23
    }
24
25 1
    public function ignore(bool $enable = true)
26
    {
27 1
        $this->setFlag('IGNORE', $enable);
28
29 1
        return $this;
30
    }
31
32
33 1
    public function getStatement(): string
34
    {
35
        return 'INSERT'
36 1
               . $this->flags->build()
37 1
               . " INTO {$this->table} "
38 1
               . $this->columns->build()
39 1
               . $this->returning->build();
40
    }
41
42
    /**
43
     * @param string|null $name
44
     *
45
     * @return string
46
     */
47 1
    public function getLastInsertId(string $name = null)
48
    {
49 1
        return $this->connection->lastInsertId($name);
50
    }
51
}
52