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

SelectMethod   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

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 0
loc 39
wmc 17
lcom 1
cbo 1
ccs 0
cts 13
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A select() 0 16 3
factory() 0 1 ?
cloneWith() 0 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
trait SelectMethod
14
{
15
    /**
16
     * @param string $columns
17
     *
18
     * @return static
19
     *
20
     * @throws LogicException
21
     */
22
    public function select($columns = "*")
23
    {
24
        if (!isset($this->table)) {
25
            throw new LogicException("select() called before table()");
26
        }
27
28
        if (!is_array($columns)) {
29
            $columns = [$columns];
30
        }
31
32
        $query = $this->factory()->newSelect();
33
        $query->from($this->table);
34
        $query->cols($columns);
35
36
        return $this->cloneWith("query", $query);
37
    }
38
39
    /**
40
     * @return QueryFactory
41
     */
42
    abstract protected function factory();
43
44
    /**
45
     * @param string $key
46
     * @param mixed $value
47
     *
48
     * @return static
49
     */
50
    abstract protected function cloneWith($key, $value);
51
}
52