Passed
Pull Request — master (#48)
by Aleksei
11:05
created

CompareProcessor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 14
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAsWhereArguments() 0 6 1
A validateArguments() 0 4 2
1
<?php
2
3
namespace Yiisoft\Yii\Cycle\DataReader\Processor;
4
5
use Cycle\ORM\Select\QueryBuilder;
6
use Yiisoft\Data\Reader\Filter\FilterProcessorInterface;
7
8
abstract class CompareProcessor implements QueryBuilderProcessor, FilterProcessorInterface
9
{
10
    protected function validateArguments(array $arguments): void
11
    {
12
        if (count($arguments) !== 2) {
13
            throw new \InvalidArgumentException('$arguments should contain exactly two elements.');
14
        }
15
    }
16
    public function getAsWhereArguments(array $arguments, array $processors): array
17
    {
18
        $this->validateArguments($arguments);
19
        [$field, $value] = $arguments;
20
21
        return [$field, $this->getOperator(), $value];
22
    }
23
}
24