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

SelectMethod   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 90%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 16
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 39
ccs 9
cts 10
cp 0.9
rs 10

3 Methods

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