Passed
Push — master ( 1f27ac...52075a )
by Alexander
04:53 queued 02:24
created

In::toCriteriaArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Data\Reader\Filter;
6
7
use Yiisoft\Data\Reader\FilterAssert;
8
use Yiisoft\Data\Reader\FilterInterface;
9
10
/**
11
 * `In` filter defines a criteria for ensuring field value matches one of the value provided.
12
 */
13
final class In implements FilterInterface
14
{
15
    /**
16
     * @var bool[]|float[]|int[]|string[] Values to check against.
17
     */
18
    private array $values;
19
20
    /**
21
     * @param string $field Name of the field to compare.
22
     * @param bool[]|float[]|int[]|string[] $values Values to check against.
23
     */
24 9
    public function __construct(private string $field, array $values)
25
    {
26 9
        foreach ($values as $value) {
27 9
            FilterAssert::isScalar($value);
28
        }
29 5
        $this->values = $values;
30
    }
31
32 5
    public function toCriteriaArray(): array
33
    {
34 5
        return [self::getOperator(), $this->field, $this->values];
35
    }
36
37 107
    public static function getOperator(): string
38
    {
39 107
        return 'in';
40
    }
41
}
42