Passed
Push — master ( 08bc9e...109825 )
by Simone
02:13
created

Validator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setData() 0 4 1
A setConstraints() 0 4 1
A validate() 0 23 2
A error() 0 4 1
1
<?php
2
3
namespace Sensorario\Resources\Tools;
4
5
use Sensorario\Resources\Configurator;
6
use Sensorario\Resources\Container;
7
use Sensorario\Resources\Resource;
8
9
class Validator
10
{
11
    private $data;
12
13
    private $constraints;
14
15
    private $error;
16
17
    public function setData(array $data)
18
    {
19
        $this->data = $data;
20
    }
21
22
    public function setConstraints(array $constraints)
23
    {
24
        $this->constraints = $constraints;
25
    }
26
27
    public function validate()
28
    {
29
        try {
30
            Resource::box(
31
                $this->data,
32
                new Configurator(
33
                    'resource',
34
                    new Container(array(
35
                        'resources' => array(
36
                            'resource' => array(
37
                                'constraints' => $this->constraints
38
                            )
39
                        )
40
                    ))
41
                )
42
            );
43
44
            return Response::success();
45
        } catch (\Exception $e) {
46
            $this->error = $e->getMessage();
47
            return Response::failure();
48
        }
49
    }
50
51
    public function error()
52
    {
53
        return $this->error;
54
    }
55
}
56