Completed
Push — master ( 755d2f...4eddf0 )
by Christopher
05:22
created

InsertMethod   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A insert() 12 12 2
factory() 1 1 ?
cloneWith() 1 1 ?

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 Aura\SqlQuery\QueryInterface;
7
use LogicException;
8
9
/**
10
 * @property string $table
11
 * @property QueryInterface $query
12
 */
13 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...
14
{
15
    /**
16
     * @param array $data
17
     *
18
     * @return static
19
     *
20
     * @throws LogicException
21
     */
22
    public function insert(array $data)
23
    {
24
        if (!isset($this->table)) {
25
            throw new LogicException("insert() called before table()");
26
        }
27
28
        $query = $this->factory()->newInsert();
29
        $query->into($this->table);
30
        $query->cols($data);
31
32
        return $this->cloneWith("query", $query);
33
    }
34
35
    /**
36
     * @return QueryFactory
37
     */
38
    abstract protected function factory();
39
40
    /**
41
     * @param string $key
42
     * @param mixed $value
43
     *
44
     * @return static
45
     */
46
    abstract protected function cloneWith($key, $value);
47
}
48