Test Failed
Pull Request — master (#147)
by Simone
01:55
created

RewriteValues::check()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 9.2876

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 15
ccs 4
cts 9
cp 0.4444
rs 8.8571
cc 5
eloc 8
nc 5
nop 1
crap 9.2876
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 RewriteValues implements Validator
18
{
19 12
    public function check(Resource $resource)
20
    {
21 12
        foreach ($resource->properties() as $key => $value) {
22 8
            if (isset($resource->rewrites()[$key])) {
23
                $when = $resource->rewrites()[$key]['when']; 
24
                $set = $resource->rewrites()[$key]['set']; 
25
26
                if (isset($when['greater_than'])) {
27
                    if ($resource->get($key) > $resource->get($when['greater_than'])) {
28
                        $resource->set($key, $resource->get($set['equals_to']));
29
                    }
30
                }
31
            }
32
        }
33 12
    }
34
}
35