Passed
Push — master ( 0b9717...65bc60 )
by noitran
05:28
created

ApplyIfArray::isSatisfiedBy()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Noitran\RQL\Processors\Eloquent;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Noitran\RQL\Contracts\Expression\ExprInterface;
7
use Noitran\RQL\Contracts\Processor\SpecInterface;
8
use Noitran\RQL\Contracts\Processor\ProcessorInterface;
9
10
/**
11
 * Class ApplyIfArray
12
 */
13
class ApplyIfArray implements SpecInterface
14
{
15
    /**
16
     * @inheritdoc
17
     */
18 5
    public function isSatisfiedBy(ProcessorInterface $processor, ExprInterface $exprClass): bool
19
    {
20 5
        if (! in_array($exprClass->getExpression(), ['$in', '$notIn', '$between'], true)) {
21 1
            return false;
22
        }
23
24 4
        return true;
25
    }
26
27
    /**
28
     * @inheritdoc
29
     */
30 4
    public function apply(ProcessorInterface $processor, ExprInterface $exprClass): Builder
31
    {
32
        /** @var EloquentProcessor $processor */
33 4
        $method = $processor::getMethodMap()[$exprClass->getExpression()];
34
35 4
        return $processor->getBuilder()->{$method}(
36 4
            $exprClass->getColumn(),
37 4
            $exprClass->getValue()
38
        );
39
    }
40
}
41