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

MandatoryProperty   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 11 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