Passed
Push — master ( 8a5d70...d3fd03 )
by Timon
02:29
created

GetField   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 19
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A toArray() 0 20 2
1
<?php
2
3
namespace TBolier\RethinkQL\Query\Manipulation;
4
5
use TBolier\RethinkQL\Query\AbstractQuery;
6
use TBolier\RethinkQL\Query\Aggregation\AggregationTrait;
7
use TBolier\RethinkQL\Query\Operation\OperationTrait;
8
use TBolier\RethinkQL\Query\QueryInterface;
9
use TBolier\RethinkQL\Query\Transformation\TransformationTrait;
10
use TBolier\RethinkQL\RethinkInterface;
11
use TBolier\RethinkQL\Types\Term\TermType;
12
13
class GetField extends AbstractQuery
14
{
15
    use AggregationTrait;
16
    use OperationTrait;
17
    use TransformationTrait;
18
19
    /**
20
     * @var string
21
     */
22
    private $field;
23
24
    /**
25
     * @var QueryInterface|null
26
     */
27
    private $query;
28
29
    public function __construct(
30
        RethinkInterface $rethink,
31
        string $field,
32
        ?QueryInterface $query = null
33
    ) {
34
        parent::__construct($rethink);
35
36
        $this->field = $field;
37
        $this->rethink = $rethink;
38
39
        $this->query = $query;
40
    }
41
42
    public function toArray(): array
43
    {
44
        if ($this->query !== null) {
45
            return [
46
                TermType::GET_FIELD,
47
                [
48
                    $this->query->toArray(),
49
                    $this->field,
50
                ],
51
            ];
52
        }
53
54
        return [
55
            TermType::GET_FIELD,
56
            [
57
                [
58
                    TermType::IMPLICIT_VAR,
59
                    [],
60
                ],
61
                $this->field,
62
            ],
63
        ];
64
    }
65
}
66