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

InsertMethod::cloneWith()

Size

Total Lines 1

Duplication

Lines 1
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 1
loc 1
ccs 0
cts 0
cp 0
nc 1
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