Passed
Pull Request — development (#682)
by Thomas
06:58
created

Validator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Oc\Validator;
4
5
use Oc\Validator\Exception\ValidationException;
6
use Symfony\Component\Validator\Validator\ValidatorInterface;
7
8
class Validator
9
{
10
    /**
11
     * @var ValidatorInterface
0 ignored issues
show
introduced by
ValidatorInterface => \Symfony\Component\Validator\Validator\ValidatorInterface
Loading history...
12
     */
13
    private $validator;
14
15
    /**
16
     * Validator constructor.
17
     *
18
     * @param ValidatorInterface $validator
0 ignored issues
show
introduced by
ValidatorInterface => \Symfony\Component\Validator\Validator\ValidatorInterface
Loading history...
19
     */
20
    public function __construct(ValidatorInterface $validator)
21
    {
22
        $this->validator = $validator;
23
    }
24
25
    /**
26
     * Validates a single item.
27
     *
28
     * @param mixed $item Item to validate
0 ignored issues
show
Coding Style Documentation introduced by
Parameter comment must end with a full stop
Loading history...
29
     *
30
     * @return void
31
     *
32
     * @throws ValidationException
0 ignored issues
show
introduced by
ValidationException => \Oc\Validator\Exception\ValidationException
Loading history...
33
     */
34
    public function validate($item)
35
    {
36
        $violations = $this->validator->validate($item);
37
38
        if ($violations->count() !== 0) {
39
            throw new ValidationException($violations);
40
        }
41
    }
42
}
43