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

OrderByMethod   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A orderBy() 0 15 3
cloneWith() 0 1 ?
1
<?php
2
3
namespace AsyncPHP\Icicle\Database\Builder\Method;
4
5
use Aura\SqlQuery\Common\SelectInterface;
6
use LogicException;
7
8
/**
9
 * @property string $table
10
 * @property SelectInterface $query
11
 */
12
trait OrderByMethod
13
{
14
    /**
15
     * @param string $order
16
     *
17
     * @return static
18
     *
19
     * @throws LogicException
20
     */
21
    public function orderBy($order)
22
    {
23
        if (!isset($this->query)) {
24
            throw new LogicException("orderBy() called before select()");
25
        }
26
27
        if (!is_array($order)) {
28
            $order = [$order];
29
        }
30
31
        $query = clone $this->query;
32
        $query->orderBy($order);
33
34
        return $this->cloneWith("query", $query);
35
    }
36
37
    /**
38
     * @param string $key
39
     * @param mixed $value
40
     *
41
     * @return static
42
     */
43
    abstract protected function cloneWith($key, $value);
44
}
45