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

RewriteValues   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
c 1
b 1
f 0
lcom 0
cbo 1
dl 0
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B check() 0 15 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 RuntimeException;
15
use Sensorario\Resources\Resource;
16
use Sensorario\Resources\Validators\Interfaces\Validator;
17
18
final class RewriteValues implements Validator
19
{
20
    public static function check(Resource $resource)
21
    {
22
        foreach ($resource->properties() as $key => $value) {
23
            if (isset($resource->rewrites()[$key])) {
24
                $when = $resource->rewrites()[$key]['when']; 
25
                $set = $resource->rewrites()[$key]['set']; 
26
27
                if (isset($when['greater_than'])) {
28
                    if ($resource->get($key) > $resource->get($when['greater_than'])) {
29
                        $resource->set($key, $resource->get($set['equals_to']));
30
                    }
31
                }
32
            }
33
        }
34
    }
35
}
36