AllowedValues   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 18
ccs 10
cts 10
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 15 4
1
<?php
2
3
/**
4
 * This file is part of sensorario/resources repository
5
 *
6
 * (c) Simone Gentili <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sensorario\Resources\Validators\Validators;
13
14
use Sensorario\Resources\Resource;
15
use Sensorario\Resources\Validators\Interfaces\Validator;
16
17
final class AllowedValues implements Validator
18
{
19 29
    public function check(Resource $resource)
20
    {
21 29
        foreach ($resource->properties() as $key => $value) {
22 20
            if (isset($resource->allowedValues()[$key])) {
23 4
                $allowedValues = $resource->allowedValues()[$key];
24 4
                if (!in_array($value, $allowedValues)) {
25 1
                    throw new \Sensorario\Resources\Exceptions\UnexpectedValueException(
26 1
                        'Value `' . $value . '` is not allowed '
27 1
                        . 'for key `' . $key . '`. '
28 20
                        . 'Allowed values are: ' . var_export($allowedValues, true)
29
                    );
30
                }
31
            }
32
        }
33 28
    }
34
}
35