Failed Conditions
Pull Request — master (#69)
by Timon
02:28
created

RowHasFields::toArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 18
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
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 RowHasFields extends AbstractQuery
15
{
16
    /**
17
     * @var array
18
     */
19
    private $keys;
20
21
    public function __construct(
22
        RethinkInterface $rethink,
23
        array $keys
24
    ) {
25
        parent::__construct($rethink);
26
27
        $this->keys    = $keys;
28
        $this->rethink = $rethink;
29
    }
30
31
    public function toArray(): array
32
    {
33
        if (\count($this->keys) === 1) {
34
            $keysQuery = implode($this->keys);
35
        } else {
36
            $keysQuery =  [
37
                TermType::MAKE_ARRAY,
38
                array_values($this->keys)
39
            ];
40
        }
41
42
        return [
43
            TermType::HAS_FIELDS,
44
            [
45
                [
46
                    TermType::IMPLICIT_VAR
47
                ],
48
                $keysQuery
49
            ]
50
        ];
51
    }
52
}
53