Passed
Pull Request — master (#18)
by Timon
05:57 queued 02:54
created

AbstractQuery::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace TBolier\RethinkQL\Query;
5
6
use TBolier\RethinkQL\Message\MessageInterface;
7
use TBolier\RethinkQL\Response\Cursor;
8
use TBolier\RethinkQL\Response\ResponseInterface;
9
use TBolier\RethinkQL\RethinkInterface;
10
11
abstract class AbstractQuery implements QueryInterface
12
{
13
    /**
14
     * @var MessageInterface
15
     */
16
    protected $message;
17
18
    /**
19
     * @var RethinkInterface
20
     */
21
    protected $rethink;
22
23
    /**
24
     * @param RethinkInterface $rethink
25
     * @param MessageInterface $message
26
     */
27 13
    public function __construct(RethinkInterface $rethink, MessageInterface $message = null)
28
    {
29 13
        $this->rethink = $rethink;
30 13
        $this->message = $message;
31 13
    }
32
33
    /**
34
     * @return \Iterable|ResponseInterface
35
     */
36 13
    public function run()
37
    {
38 13
        $this->message->setQuery($this->toArray());
39
40 13
        return $this->rethink->connection()->run($this->message);
41
    }
42
43
    /**
44
     * @return array
45
     */
46
    abstract public function toArray(): array;
47
}
48