Test Failed
Pull Request — master (#147)
by Simone
01:55
created

AllowedRanges   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 33.33%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 20
ccs 4
cts 12
cp 0.3333
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 12
    public function check(Resource $resource)
20
    {
21 12
        foreach ($resource->properties() as $key => $value) {
22 8
            if (isset($resource->ranges()[$key])) {
23
                if ($value < $resource->ranges()[$key]['more_than']) {
24
                    throw new \Sensorario\Resources\Exceptions\OutOfRangeException(
25
                        'Value `' . $value . '` is out of range: '
26
                        . '`'
27
                        . $resource->ranges()[$key]['more_than']
28
                        . ' to '
29
                        . $resource->ranges()[$key]['more_than']
30
                        . '`.'
31
                    );
32
                }
33
            }
34
        }
35 12
    }
36
}
37