Failed Conditions
Pull Request — master (#74)
by Timon
03:06
created

Changes::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
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\QueryInterface;
8
use TBolier\RethinkQL\RethinkInterface;
9
use TBolier\RethinkQL\Types\Term\TermType;
10
11
class Changes extends AbstractQuery
12
{
13
    /**
14
     * @var array
15
     */
16
    private $options;
17
18
    /**
19
     * @var QueryInterface
20
     */
21
    private $query;
22
23
    public function __construct(
24
        RethinkInterface $rethink,
25
        QueryInterface $query,
26
        ?array $options
27
    ) {
28
        parent::__construct($rethink);
29
30
        $this->query = $query;
31
        $this->rethink = $rethink;
32
        $this->options = $options;
33
    }
34
35
    // [1,[152,[[15,[[14,["booking"]],"etabs"]]]],{"binary_format":"raw","time_format":"raw","profile":false}]
36
    // [1,[152,[[15,[[14,["test"]],"tabletest"]]],{"squash":true}],{"binary_format":"raw","time_format":"raw","profile":false}]
37
    public function toArray(): array
38
    {
39
        $query = [
40
            TermType::CHANGES,
41
            [
42
                $this->query->toArray(),
43
            ],
44
        ];
45
46
        if ($this->options) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->options of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
47
            array_push($query, $this->options);
48
        }
49
50
        return $query;
51
    }
52
}
53