ApplyIfArray   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

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