OrderBy::toArray()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
c 0
b 0
f 0
rs 10
cc 2
nc 2
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace TBolier\RethinkQL\Query\Transformation;
5
6
use TBolier\RethinkQL\Query\AbstractQuery;
7
use TBolier\RethinkQL\Query\Operation\OperationTrait;
8
use TBolier\RethinkQL\Query\QueryInterface;
9
use TBolier\RethinkQL\RethinkInterface;
10
use TBolier\RethinkQL\Types\Term\TermType;
11
12
class OrderBy extends AbstractQuery
13
{
14
    use TransformationTrait;
15
    use OperationTrait;
16
17
    /**
18
     * @var mixed|QueryInterface
19
     */
20
    private $key;
21
22
    /**
23
     * @var QueryInterface
24
     */
25
    private $query;
26
27
    public function __construct(
28
        RethinkInterface $rethink,
29
        QueryInterface $query,
30
        $key
31
    ) {
32
        parent::__construct($rethink);
33
34
        $this->query = $query;
35
        $this->key = $key;
36
        $this->rethink = $rethink;
37
    }
38
39
    public function toArray(): array
40
    {
41
        $ordering = $this->key instanceof QueryInterface ? $this->key->toArray() : $this->key;
42
43
        return [
44
            TermType::ORDER_BY,
45
            [
46
                $this->query->toArray(),
47
                $ordering,
48
            ],
49
        ];
50
    }
51
}
52