Passed
Push — master ( f0feee...3c09de )
by Sergei
12:22
created

In::getValues()   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
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Data\Reader\Filter;
6
7
use InvalidArgumentException;
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 6
    public function __construct(
25
        private readonly string $field,
26
        array $values
27
    ) {
28 6
        foreach ($values as $value) {
29
            /** @psalm-suppress DocblockTypeContradiction */
30 6
            if (!is_scalar($value)) {
31 1
                throw new InvalidArgumentException(
32 1
                    sprintf(
33 1
                        'The value should be scalar. "%s" is received.',
34 1
                        get_debug_type($value),
35 1
                    )
36 1
                );
37
            }
38
        }
39 5
        $this->values = $values;
40
    }
41
42 5
    public function getField(): string
43
    {
44 5
        return $this->field;
45
    }
46
47
    /**
48
     * @return bool[]|float[]|int[]|string[]
49
     */
50 5
    public function getValues(): array
51
    {
52 5
        return $this->values;
53
    }
54
}
55