Failed Conditions
Pull Request — new-parser-ast-metadata (#3)
by
unknown
06:33 queued 04:54
created

EnumConstraint::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Annotations\Assembler\Validator\Constraint;
6
7
use Doctrine\Annotations\Assembler\Validator\Constraint\Exception\InvalidValue;
8
use function in_array;
9
10
final class EnumConstraint implements Constraint
11
{
12
    /** @var mixed[] */
13
    private $allowedValues;
14
15
    /**
16
     * @param mixed[] $allowedValues
17
     */
18 2
    public function __construct(array $allowedValues)
19
    {
20 2
        $this->allowedValues = $allowedValues;
21 2
    }
22
23
    /**
24
     * @param mixed $value
25
     */
26 2
    public function validate($value) : void
27
    {
28 2
        if (in_array($value, $this->allowedValues)) {
29 1
            return;
30
        }
31
32 1
        throw InvalidValue::new($this->allowedValues, $value);
33
    }
34
}
35