Passed
Push — feature/initial-implementation ( fae671...591f29 )
by Fike
02:37
created

Violations::remap()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 17
nc 2
nop 3
1
<?php
2
3
namespace AmaTeam\ElasticSearch\Utility;
4
5
use Symfony\Component\Validator\ConstraintViolation;
6
use Symfony\Component\Validator\ConstraintViolationInterface;
7
8
class Violations
9
{
10
    public static function remap(ConstraintViolationInterface $violation, $root, string $path): ConstraintViolation
11
    {
12
        $propertyPath = $path . '.' . $violation->getPropertyPath();
13
        $cause = null;
14
        $constraint = null;
15
        if ($violation instanceof ConstraintViolation) {
16
            $cause = $violation->getCause();
17
            $constraint = $violation->getConstraint();
18
        }
19
        return new ConstraintViolation(
20
            $violation->getMessage(),
21
            $violation->getMessageTemplate(),
22
            $violation->getParameters(),
23
            $root,
24
            $propertyPath,
25
            $violation->getInvalidValue(),
26
            $violation->getPlural(),
27
            $violation->getCode(),
28
            $constraint,
29
            $cause
30
        );
31
    }
32
}
33