Completed
Push — master ( 519cfb...a79a93 )
by Nielsen
03:17
created

SQLInsert::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Softbox\Persistence\Core\SQL\Command;
4
5
use Softbox\Persistence\Core\InsertBase;
6
use Softbox\Persistence\Core\SQL\PersistenceService;
7
use Softbox\Persistence\Core\SQL\Builder\SQLConverter;
8
9
/**
10
 * Class that represents the SQL INSERT command
11
 *
12
 * @package Softbox\Persistence\Core\SQL\Command
13
 */
14
class SQLInsert extends InsertBase {
15
16
    /**
17
     * Returns an array with the possible values to be inserted
18
     *
19
     * @return array [[Key => Value] ...]
20
     */
21 1 View Code Duplication
    public function getTableValues() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22 1
        $cols = $this->persistence->getColsOfTable($this->getEntity());
23 1
        $values = [];
24 1
        foreach ($this->getValues() as $col => $val) {
25 1
            if (in_array($col, $cols)) {
26 1
                $values[$col] = $val;
27 1
            }
28 1
        }
29
30 1
        return $values;
31
    }
32
33 View Code Duplication
    public function execute() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
        $values = $this->getTableValues();
35
        if (empty($values)) {
36
            throw new SQLException("There are no values to be inserted.");
37
        }
38
        $sql = $this->build(new SQLConverter());
39
40
        return $this->persistence->exec($sql, $values);
41
    }
42
}
43