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

Validator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 8 2
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