Passed
Push — master ( cd5f33...085ce3 )
by Aleksei
02:37
created

CompareHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 17
ccs 0
cts 7
cp 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateArguments() 0 4 2
A getAsWhereArguments() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Cycle\Data\Reader\FilterHandler;
6
7
use InvalidArgumentException;
8
use Yiisoft\Data\Reader\FilterHandlerInterface;
9
use Yiisoft\Yii\Cycle\Data\Reader\QueryBuilderFilterHandler;
10
11
abstract class CompareHandler implements QueryBuilderFilterHandler, FilterHandlerInterface
12
{
13
    abstract protected function getSymbol(): string;
14
15
    protected function validateArguments(array $arguments): void
16
    {
17
        if (count($arguments) !== 2) {
18
            throw new InvalidArgumentException('$arguments should contain exactly two elements.');
19
        }
20
    }
21
22
    public function getAsWhereArguments(array $arguments, array $handlers): array
23
    {
24
        $this->validateArguments($arguments);
25
        [$field, $value] = $arguments;
26
27
        return [$field, $this->getSymbol(), $value];
28
    }
29
}
30