Passed
Push — master ( 694425...cb2fe4 )
by Marc
03:56
created

OrderBy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A toArray() 0 9 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace TBolier\RethinkQL\Query\Aggregation;
5
6
use TBolier\RethinkQL\Message\MessageInterface;
7
use TBolier\RethinkQL\Query\QueryInterface;
8
use TBolier\RethinkQL\RethinkInterface;
9
use TBolier\RethinkQL\Types\Term\TermType;
10
11
class OrderBy extends AbstractAggregation
12
{
13
    /**
14
     * @var mixed|QueryInterface
15
     */
16
    private $key;
17
18
    /**
19
     * @var QueryInterface
20
     */
21
    private $query;
22
23
    /**
24
     * @param RethinkInterface $rethink
25
     * @param MessageInterface $message
26
     * @param QueryInterface $query
27
     * @param mixed $key
28
     */
29
    public function __construct(
30
        RethinkInterface $rethink,
31
        MessageInterface $message,
32
        QueryInterface $query,
33
        $key
34
    ) {
35
        parent::__construct($rethink, $message);
36
37
        $this->query = $query;
38
        $this->key = $key;
39
        $this->rethink = $rethink;
40
        $this->message = $message;
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46
    public function toArray(): array
47
    {
48
        $ordering = $this->key instanceof QueryInterface ? $this->key->toArray() : $this->key;
49
50
        return [
51
            TermType::ORDER_BY,
52
            [
53
                $this->query->toArray(),
54
                $ordering
55
            ],
56
        ];
57
    }
58
}
59