Completed
Push — master ( ca4d17...00f2c1 )
by Simone
02:25
created

Validator::error()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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 2
    public function setData(array $data)
18
    {
19 2
        $this->data = $data;
20 2
    }
21
22 1
    public function setConstraints(array $constraints)
23
    {
24 1
        $this->constraints = $constraints;
25 1
    }
26
27 3
    public function validate()
28
    {
29
        try {
30 3
            Resource::box(
31 3
                $this->data,
32 3
                new Configurator(
33 3
                    'resource',
34 3
                    new Container(array(
35
                        'resources' => array(
36
                            'resource' => array(
37 3
                                'constraints' => $this->constraints
38
                            )
39
                        )
40
                    ))
41
                )
42
            );
43
44 2
            return Response::success();
45 1
        } catch (\Exception $e) {
46 1
            $this->error = $e->getMessage();
47 1
            return Response::failure();
48
        }
49
    }
50
51 1
    public function error()
52
    {
53 1
        return $this->error;
54
    }
55
}
56