ApplyIfArray::isSatisfiedBy()   A
last analyzed

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
declare(strict_types=1);
4
5
namespace Noitran\RQL\Processors\Eloquent;
6
7
use Illuminate\Database\Eloquent\Builder;
8
use Noitran\RQL\Contracts\Expression\ExprInterface;
9
use Noitran\RQL\Contracts\Processor\ProcessorInterface;
10
use Noitran\RQL\Contracts\Processor\SpecInterface;
11
12
/**
13
 * Class ApplyIfArray.
14
 */
15
class ApplyIfArray implements SpecInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 5
    public function isSatisfiedBy(ProcessorInterface $processor, ExprInterface $exprClass): bool
21
    {
22 5
        if (! \in_array($exprClass->getExpression(), ['$in', '$notIn', '$between'], true)) {
23 1
            return false;
24
        }
25
26 4
        return true;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 4
    public function apply(ProcessorInterface $processor, ExprInterface $exprClass): Builder
33
    {
34
        /** @var EloquentProcessor $processor */
35 4
        $method = $processor::getMethodMap()[$exprClass->getExpression()];
36
37 4
        return $processor->getBuilder()->{$method}(
38 4
            $exprClass->getColumn(),
39 4
            $exprClass->getValue()
40
        );
41
    }
42
}
43