Passed
Push — main ( ae29e3...10579d )
by Sammy
07:25
created

OrderBy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 10
c 2
b 0
f 1
dl 0
loc 35
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __toString() 0 3 1
A desc() 0 3 1
A name() 0 3 1
A asc() 0 3 1
A add() 0 5 1
1
<?php
2
3
namespace HexMakina\Crudites\Grammar\Clause;
4
5
use HexMakina\Crudites\Grammar\DeckOrderBy;
6
7
class OrderBy extends Clause
8
{
9
    private DeckOrderBy $deck;
10
11
    public function __construct($selected, string $direction)
12
    {
13
        $this->deck = new DeckOrderBy($selected, $direction);
14
    }
15
16
    public function add(...$args): self
17
    {
18
        list($selected, $direction) = $args;
19
        $this->deck->add($selected, $direction);
20
        return $this;
21
    }
22
23
    public function asc($selected): self
24
    {
25
        return $this->add([$selected, 'ASC']);
26
    }
27
28
    public function desc($selected): self
29
    {
30
        return $this->add([$selected, 'DESC']);
31
    }
32
33
    public function __toString(): string
34
    {
35
        return 'ORDER BY ' . $this->deck;
36
    }
37
38
39
    public function name(): string
40
    {
41
        return self::ORDER;
42
    }
43
}
44