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

ApplyIfArray   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 25
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A apply() 0 8 1
A isSatisfiedBy() 0 7 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