Passed
Push — master ( adcfba...df27c1 )
by Pavel
01:38
created

CanValidate   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateEntity() 0 12 2
1
<?php namespace Pz\Doctrine\Rest\Traits;
2
3
use Pz\Doctrine\Rest\Exceptions\RestException;
4
use Symfony\Component\Validator\Validation;
5
6
trait CanValidate
7
{
8
    /**
9
     * @param object $entity
10
     *
11
     * @return object
12
     * @throws RestException
13
     */
14 4
    protected function validateEntity($entity)
15
    {
16 4
        $errors = Validation::createValidatorBuilder()
17 4
            ->enableAnnotationMapping()
18 4
            ->getValidator()
19 4
            ->validate($entity);
20
21 4
        if ($errors->count() > 0) {
22 1
            throw RestException::createFromConstraintViolationList($errors);
23
        }
24
25 3
        return $entity;
26
    }
27
}
28