InExpression::evaluate()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 4
nop 2
dl 0
loc 14
ccs 8
cts 8
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * @license     http://opensource.org/licenses/mit-license.php MIT
5
 * @link        https://github.com/nicoSWD
6
 * @author      Nicolas Oelgart <[email protected]>
7
 */
8
namespace nicoSWD\Rule\Expression;
9
10
use nicoSWD\Rule\TokenStream\TokenCollection;
11
use nicoSWD\Rule\Parser\Exception\ParserException;
12
13
final class InExpression extends BaseExpression
14
{
15 10
    public function evaluate(mixed $leftValue, mixed $rightValue): bool
16
    {
17 10
        if ($rightValue instanceof TokenCollection) {
18 4
            $rightValue = $rightValue->toArray();
19
        }
20
21 10
        if (!is_array($rightValue)) {
22 2
            throw new ParserException(sprintf(
23 2
                'Expected array, got "%s"',
24 2
                gettype($rightValue)
25
            ));
26
        }
27
28 8
        return in_array($leftValue, $rightValue, strict: true);
29
    }
30
}
31