Passed
Pull Request — master (#34)
by Marc
05:44
created

Avg::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace TBolier\RethinkQL\Query\Aggregation;
5
6
use TBolier\RethinkQL\Message\MessageInterface;
7
use TBolier\RethinkQL\Query\QueryInterface;
8
use TBolier\RethinkQL\RethinkInterface;
9
use TBolier\RethinkQL\Types\Term\TermType;
10
11
class Avg extends AbstractAggregation
12
{
13
    /**
14
     * @var string
15
     */
16
    private $key;
17
18
    /**
19
     * @var QueryInterface
20
     */
21
    private $query;
22
23
    /**
24
     * @param RethinkInterface $rethink
25
     * @param MessageInterface $message
26
     * @param QueryInterface $query
27
     * @param string $key
28
     */
29
    public function __construct(
30
        RethinkInterface $rethink,
31
        MessageInterface $message,
32
        QueryInterface $query,
33
        string $key
34
    ) {
35
        parent::__construct($rethink, $message);
36
37
        $this->query = $query;
38
        $this->key = $key;
39
        $this->rethink = $rethink;
40
        $this->message = $message;
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46
    public function toArray(): array
47
    {
48
        return [
49
            TermType::AVG,
50
            [
51
                $this->query->toArray(),
52
                $this->key
53
            ],
54
        ];
55
    }
56
}
57