AllowedRanges::check()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 12
cts 12
cp 1
rs 9.7
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 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