Completed
Push — master ( 955373...14f156 )
by Simone
02:09 queued 11s
created

MandatoryProperty::check()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
crap 3
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 MandatoryProperty implements Validator
18
{
19 30
    public function check(Resource $resource)
20
    {
21 30
        foreach ($resource->mandatory() as $key => $value) {
22 17
            if (isset($value['when']['condition'])) {
23 2
                throw new \Sensorario\Resources\Exceptions\PropertyNotSetException(
24 2
                    "Property `" . get_class($resource)
25 2
                    . "::\${$key}` is mandatory but not set"
26
                );
27
            }
28
        }
29 28
    }
30
}
31