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

ApplyIfArray::apply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
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