AllowedRanges   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
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 20
ccs 12
cts 12
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 17 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 AllowedRanges implements Validator
18
{
19 28
    public function check(Resource $resource)
20
    {
21 28
        foreach ($resource->properties() as $key => $value) {
22 19
            if (isset($resource->ranges()[$key])) {
23 1
                if ($value < $resource->ranges()[$key]['more_than']) {
24 1
                    throw new \Sensorario\Resources\Exceptions\OutOfRangeException(
25 1
                        'Value `' . $value . '` is out of range: '
26 1
                        . '`'
27 1
                        . $resource->ranges()[$key]['more_than']
28 1
                        . ' to '
29 1
                        . $resource->ranges()[$key]['more_than']
30 19
                        . '`.'
31
                    );
32
                }
33
            }
34
        }
35 27
    }
36
}
37