Passed
Push — master ( e0d17a...139da0 )
by Michel
03:37
created

Row   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 10
dl 0
loc 131
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A eq() 0 18 2
A ne() 0 18 2
A gt() 0 18 2
A __construct() 0 10 1
A toArray() 0 3 1
A lt() 0 18 2
1
<?php
2
declare(strict_types=1);
3
4
namespace TBolier\RethinkQL\Query;
5
6
use TBolier\RethinkQL\Message\MessageInterface;
7
use TBolier\RethinkQL\Query\Exception\QueryException;
8
use TBolier\RethinkQL\Query\Logic\EqualLogic;
9
use TBolier\RethinkQL\Query\Logic\FuncLogic;
10
use TBolier\RethinkQL\Query\Logic\GetFieldLogic;
11
use TBolier\RethinkQL\Query\Logic\GreaterThanLogic;
12
use TBolier\RethinkQL\Query\Logic\LowerThanLogic;
13
use TBolier\RethinkQL\Query\Logic\NotEqualLogic;
14
use TBolier\RethinkQL\Query\Manipulation\ManipulationInterface;
15
use TBolier\RethinkQL\RethinkInterface;
16
17
class Row extends AbstractQuery implements ManipulationInterface
18
{
19
    /**
20
     * @var QueryInterface
21
     */
22
    private $query;
23
24
    /**
25
     * @var string
26
     */
27
    private $value;
28
29
    /**
30
     * @param RethinkInterface $rethink
31
     * @param MessageInterface $message
32
     * @param string $value
33
     */
34
    public function __construct(
35
        RethinkInterface $rethink,
36
        MessageInterface $message,
37
        string $value
38
    ) {
39
        parent::__construct($rethink, $message);
40
41
        $this->value = $value;
42
        $this->rethink = $rethink;
43
        $this->message = $message;
44
    }
45
46
    /**
47
     * @inheritdoc
48
     * @throws QueryException
49
     */
50
    public function eq($value): QueryInterface
51
    {
52
        if (!\is_scalar($value)) {
53
            throw new QueryException('Only scalar types are supported for lower than manipulations.');
54
        }
55
56
        $this->query = new FuncLogic(
57
            $this->rethink,
58
            $this->message,
59
            new EqualLogic(
60
                $this->rethink,
61
                $this->message,
62
                new GetFieldLogic($this->rethink, $this->message, $this->value),
63
                $value
64
            )
65
        );
66
67
        return $this->query;
68
    }
69
70
    /**
71
     * @inheritdoc
72
     * @throws QueryException
73
     */
74
    public function ne($value): QueryInterface
75
    {
76
        if (!\is_scalar($value)) {
77
            throw new QueryException('Only scalar types are supported for lower than manipulations.');
78
        }
79
80
        $this->query = new FuncLogic(
81
            $this->rethink,
82
            $this->message,
83
            new NotEqualLogic(
84
                $this->rethink,
85
                $this->message,
86
                new GetFieldLogic($this->rethink, $this->message, $this->value),
87
                $value
88
            )
89
        );
90
91
        return $this->query;
92
    }
93
94
    /**
95
     * @inheritdoc
96
     * @throws QueryException
97
     */
98
    public function lt($value): QueryInterface
99
    {
100
        if (!\is_scalar($value)) {
101
            throw new QueryException('Only scalar types are supported for lower than manipulations.');
102
        }
103
104
        $this->query = new FuncLogic(
105
            $this->rethink,
106
            $this->message,
107
            new LowerThanLogic(
108
                $this->rethink,
109
                $this->message,
110
                new GetFieldLogic($this->rethink, $this->message, $this->value),
111
                $value
112
            )
113
        );
114
115
        return $this->query;
116
    }
117
118
    /**
119
     * @inheritdoc
120
     * @throws QueryException
121
     */
122
    public function gt($value): QueryInterface
123
    {
124
        if (!\is_scalar($value)) {
125
            throw new QueryException('Only scalar types are supported for greater than manipulations.');
126
        }
127
128
        $this->query = new FuncLogic(
129
            $this->rethink,
130
            $this->message,
131
            new GreaterThanLogic(
132
                $this->rethink,
133
                $this->message,
134
                new GetFieldLogic($this->rethink, $this->message, $this->value),
135
                $value
136
            )
137
        );
138
139
        return $this->query;
140
    }
141
142
    /**
143
     * @inheritdoc
144
     */
145
    public function toArray(): array
146
    {
147
        return $this->query->toArray();
148
    }
149
}
150