Failed Conditions
Pull Request — master (#32)
by Timon
03:20
created

OrderBy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 4
1
<?php
2
declare(strict_types = 1);
3
4
namespace TBolier\RethinkQL\Query\Aggregation;
5
6
use MongoDB\Driver\Query;
7
use TBolier\RethinkQL\Message\MessageInterface;
8
use TBolier\RethinkQL\Query\QueryInterface;
9
use TBolier\RethinkQL\RethinkInterface;
10
use TBolier\RethinkQL\Types\Term\TermType;
11
12
class OrderBy extends AbstractAggregation
13
{
14
    /**
15
     * @var string
16
     */
17
    private $key;
18
19
    /**
20
     * @var QueryInterface
21
     */
22
    private $query;
23
24
    /**
25
     * @param RethinkInterface $rethink
26
     * @param MessageInterface $message
27
     * @param QueryInterface $query
28
     * @param mixed $key
29
     */
30
    public function __construct(
31
        RethinkInterface $rethink,
32
        MessageInterface $message,
33
        QueryInterface $query,
34
        $key
35
    ){
0 ignored issues
show
Coding Style introduced by
There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces
Loading history...
36
        parent::__construct($rethink, $message);
37
38
        $this->query = $query;
39
        $this->key = $key;
40
        $this->rethink = $rethink;
41
        $this->message = $message;
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function toArray(): array
48
    {
49
        $ordering = $this->key instanceof QueryInterface ? $this->key->toArray() : $this->key;
0 ignored issues
show
introduced by
The condition $this->key instanceof TB...QL\Query\QueryInterface can never be true since $this->key is never a sub-type of TBolier\RethinkQL\Query\QueryInterface.
Loading history...
50
51
        return [
52
            TermType::ORDER_BY,
53
            [
54
                $this->query->toArray(),
55
                $ordering
56
            ],
57
        ];
58
    }
59
}
60