Enum   A
last analyzed

Coupling/Cohesion

Components 0
Dependencies 2

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B validate() 0 18 6
1
<?php
2
3
namespace League\JsonGuard\Constraint\DraftFour;
4
5
use League\JsonGuard\Assert;
6
use League\JsonGuard\ConstraintInterface;
7
use League\JsonGuard\Validator;
8
use function League\JsonGuard\error;
9
10
final class Enum implements ConstraintInterface
11
{
12
    const KEYWORD = 'enum';
13
14
    /**
15
     * {@inheritdoc}
16
     */
17 8
    public function validate($value, $parameter, Validator $validator)
18
    {
19 8
        Assert::type($parameter, 'array', self::KEYWORD, $validator->getSchemaPath());
20
21 4
        if (is_object($value)) {
22 2
            foreach ($parameter as $i) {
23 2
                if (is_object($i) && $value == $i) {
24 1
                    return null;
25
                }
26 1
            }
27 1
        } else {
28 4
            if (in_array($value, $parameter, true)) {
29 4
                return null;
30
            }
31
        }
32
33 4
        return error('The value must be one of: {parameter}', $validator);
34
    }
35
}
36