Test Failed
Push — master ( 2160b1...e71542 )
by Anatoly
09:43 queued 10s
created

ValidatorService   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 22
c 1
b 0
f 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 9 2
1
<?php declare(strict_types=1);
2
3
namespace App\Service;
4
5
/**
6
 * Import classes
7
 */
8
use App\ContainerAwareTrait;
9
use App\Exception\InvalidEntityException;
10
11
/**
12
 * ValidatorService
13
 */
14
final class ValidatorService
15
{
16
    use ContainerAwareTrait;
17
18
    /**
19
     * Validates the given entity
20
     *
21
     * @param object $entity
22
     *
23
     * @return void
24
     *
25
     * @throws InvalidEntityException
26
     */
27
    public function validate(object $entity) : void
28
    {
29
        $violations = $this->container->get('validator')->validate($entity);
30
31
        if (0 === $violations->count()) {
32
            return;
33
        }
34
35
        throw new InvalidEntityException($entity, $violations);
36
    }
37
}
38