Completed
Push — master ( 6f7871 )
by Simone
02:56
created

AllowedRanges::check()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 9.2
cc 4
eloc 11
nc 4
nop 1
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 RuntimeException;
15
use Sensorario\Resources\Resource;
16
use Sensorario\Resources\Validators\Interfaces\Validator;
17
18
final class AllowedRanges implements Validator
19
{
20
    public static function check(Resource $resource)
21
    {
22
        foreach ($resource->properties() as $key => $value) {
23
            if (isset($resource->ranges()[$key])) {
24
                if ($value < $resource->ranges()[$key]['more_than']) {
25
                    throw new RuntimeException(
26
                        'Value `' . $value . '` is out of range: '
27
                        . '`'
28
                        . $resource->ranges()[$key]['more_than']
29
                        . ' to '
30
                        . $resource->ranges()[$key]['more_than']
31
                        . '`.'
32
                    );
33
                }
34
            }
35
        }
36
    }
37
}
38