Completed
Push — master ( d819e3...4fe283 )
by Christopher
03:01 queued 12s
created

InsertMethod   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 85.71%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 1
dl 35
loc 35
ccs 6
cts 7
cp 0.8571
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
factory() 1 1 ?
cloneWith() 1 1 ?
A insert() 12 12 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 AsyncPHP\Icicle\Database\Builder\Method;
4
5
use Aura\SqlQuery\QueryFactory;
6
use LogicException;
7
8
/**
9
 * @property string $table
10
 */
11 View Code Duplication
trait InsertMethod
0 ignored issues
show
Duplication introduced by
This class 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...
12
{
13
    /**
14
     * @param array $data
15
     *
16
     * @return static
17
     *
18
     * @throws LogicException
19
     */
20 1
    public function insert(array $data)
21
    {
22 1
        if (!isset($this->table)) {
23
            throw new LogicException("insert() called before table()");
24
        }
25
26 1
        $query = $this->factory()->newInsert();
27 1
        $query->into($this->table);
28 1
        $query->cols($data);
29
30 1
        return $this->cloneWith("query", $query);
31
    }
32
33
    /**
34
     * @return QueryFactory
35
     */
36
    abstract protected function factory();
37
38
    /**
39
     * @param string $key
40
     * @param mixed $value
41
     *
42
     * @return static
43
     */
44
    abstract protected function cloneWith($key, $value);
45
}
46