Completed
Push — master ( 51150e...71a2a1 )
by Simone
02:00
created

MandatoryProperty   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B check() 0 16 5
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 $mandatoryProperty => $value) {
22 17
            if (isset($value['when']['condition'])) {
23 2
                $when = $value['when'];
24 2
                if ('is_present' == $when['condition']) {
25 2
                    if (!$resource->hasProperty($mandatoryProperty)) {
26 2
                        throw new \Sensorario\Resources\Exceptions\PropertyNotSetException(
27 2
                            "Property `" . get_class($resource)
28 17
                            . "::\${$mandatoryProperty}` is mandatory but not set"
29
                        );
30
                    }
31
                }
32
            }
33
        }
34 28
    }
35
}
36