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

HasFields   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

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

2 Methods

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