Failed Conditions
Pull Request — new-parser-ast-metadata (#3)
by
unknown
01:53
created

EnumConstraint   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 4
dl 0
loc 20
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A validate() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Annotations\Metadata\Constraint;
6
7
use function in_array;
8
9
final class EnumConstraint implements Constraint
10
{
11
    /** @var mixed[] */
12
    private $allowedValues;
13
14
    /**
15
     * @param mixed[] $allowedValues
16
     */
17 3
    public function __construct(array $allowedValues)
18
    {
19 3
        $this->allowedValues = $allowedValues;
20 3
    }
21
22
    /**
23
     * @param mixed $value
24
     */
25 2
    public function validate($value) : void
26
    {
27 2
        if (! in_array($value, $this->allowedValues)) {
28 1
            throw InvalidValue::new($this->allowedValues, $value);
29
        }
30 1
    }
31
}
32