Completed
Push — master ( 8b8539...de5cc9 )
by Tristan
13:08 queued 08:55
created

UUIDValidator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 31
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 17 4
1
<?php
2
3
namespace Nicofuma\SwaggerBundle\JsonSchema\Constraints\Format;
4
5
use Nicofuma\SwaggerBundle\Exception\FormatConstraintException;
6
use Symfony\Component\Validator\Constraints\Uuid;
7
use Symfony\Component\Validator\ConstraintViolation;
8
use Symfony\Component\Validator\Validator\ValidatorInterface;
9
10
class UUIDValidator implements FormatValidatorInterface
11
{
12
    /** @var ValidatorInterface */
13
    private $validator;
14
15 2
    public function __construct(ValidatorInterface $validator = null)
16
    {
17 2
        $this->validator = $validator;
18 2
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23 2
    public function validate($value)
24
    {
25 2
        if ($this->validator !== null) {
26 2
            $errorList = $this->validator->validate($value, [new Uuid()]);
27
28 2
            if (count($errorList) > 0) {
29 1
                $errors = [];
30
31
                /** @var ConstraintViolation $error */
32 1
                foreach ($errorList as $error) {
33 1
                    $errors[] = $error->getMessage();
34 1
                }
35
36 1
                throw new FormatConstraintException($errors);
37
            }
38 1
        }
39 1
    }
40
}
41