Passed
Push — master ( 8cb90e...59fa3d )
by Timon
08:19 queued 05:53
created

Between::toArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 15
rs 9.9666
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\Operation;
5
6
use TBolier\RethinkQL\Query\AbstractQuery;
7
use TBolier\RethinkQL\Query\Aggregation\AggregationTrait;
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 Between extends AbstractQuery
14
{
15
    use AggregationTrait;
16
    use OperationTrait;
17
    use TransformationTrait;
18
19
    /**
20
     * @var QueryInterface
21
     */
22
    private $query;
23
24
    /**
25
     * @var string
26
     */
27
    private $min;
28
29
    /**
30
     * @var string
31
     */
32
    private $max;
33
34
    /**
35
     * @var array|null
36
     */
37
    private $options;
38
39
    public function __construct(
40
        RethinkInterface $rethink,
41
        QueryInterface $query,
42
        $min,
43
        $max,
44
        array $options = null
45
    ) {
46
        parent::__construct($rethink);
47
48
        $this->rethink = $rethink;
49
        $this->query = $query;
50
        $this->min = $min;
51
        $this->max = $max;
52
        $this->options = $options;
53
    }
54
55
    public function toArray(): array
56
    {
57
        $args = [
58
            $this->query->toArray(),
59
            $this->min,
60
            $this->max,
61
        ];
62
63
        if ($this->options !== null) {
64
            $args = array_merge($args, [$this->options]);
65
        }
66
67
        return [
68
            TermType::BETWEEN,
69
            $args,
70
        ];
71
    }
72
}
73