Passed
Pull Request — development (#682)
by Nick
07:18
created

Validator::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 9.4285
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
/**
9
 * Class Validator
10
 *
11
 * @package Oc\Validator
0 ignored issues
show
introduced by
Unexpected tag type @package in doc block
Loading history...
12
 */
13
class Validator
14
{
15
    /**
16
     * @var ValidatorInterface
0 ignored issues
show
introduced by
ValidatorInterface => \Symfony\Component\Validator\Validator\ValidatorInterface
Loading history...
17
     */
18
    private $validator;
19
20
    /**
21
     * Validator constructor.
22
     *
23
     * @param ValidatorInterface $validator
0 ignored issues
show
introduced by
ValidatorInterface => \Symfony\Component\Validator\Validator\ValidatorInterface
Loading history...
24
     */
25
    public function __construct(ValidatorInterface $validator)
26
    {
27
        $this->validator = $validator;
28
    }
29
30
    /**
31
     * Validates a single item.
32
     *
33
     * @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...
34
     *
35
     * @return void
36
     *
37
     * @throws ValidationException
0 ignored issues
show
introduced by
ValidationException => \Oc\Validator\Exception\ValidationException
Loading history...
38
     */
39
    public function validate($item)
40
    {
41
        $violations = $this->validator->validate($item);
42
43
        if ($violations->count() !== 0) {
44
            throw new ValidationException($violations);
45
        }
46
    }
47
}
48