Completed
Push — master ( f3d932...88ba9b )
by Dmitry
03:14
created

QueryMutator::apply()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 0
cts 9
cp 0
rs 9.4285
cc 3
eloc 6
nc 4
nop 1
crap 12
1
<?php
2
3
4
namespace hiapi\query;
5
6
class QueryMutator
7
{
8
    /**
9
     * @var \yii\db\Query
10
     */
11
    protected $query;
12
13
    /**
14
     * QueryMutator constructor.
15
     * @param \yii\db\Query $query
16
     */
17
    public function __construct($query)
18
    {
19
        $this->query = $query;
20
    }
21
22
    public function apply(Specification $specification)
23
    {
24
        if ($specification->where) {
25
            $this->query->andWhere($specification->where);
26
        }
27
28
        if ($specification->limit) {
29
            $this->query->limit($specification->limit);
30
        }
31
32
        return $this;
33
    }
34
35
    public function getQuery()
36
    {
37
        return $this->query;
38
    }
39
}
40