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

SQLInsert   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 68.97 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 20
loc 29
ccs 9
cts 15
cp 0.6
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTableValues() 11 11 3
A execute() 9 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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