Passed
Pull Request — master (#21)
by Pavel
06:33
created

EntityProcessingException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 34
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A invalidDataSubmitted() 0 6 1
A fromViolationList() 0 18 2
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Exception;
4
5
use Symfony\Component\Validator\ConstraintViolationInterface;
6
use Symfony\Component\Validator\ConstraintViolationListInterface;
7
use Symfony\Component\Yaml\Yaml;
8
9
class EntityProcessingException extends \RuntimeException implements CrudsExceptionInterface
10
{
11
    /**
12
     * @param string $message
13
     *
14
     * @return static
15
     */
16
    public static function invalidDataSubmitted($message)
17
    {
18
        return new static(
19
            sprintf('Data submitted to processor is invalid: %s', $message)
20
        );
21
    }
22
23
    public static function fromViolationList(ConstraintViolationListInterface $list)
24
    {
25
        $errors = [];
26
        foreach ($list as $violation) {
27
            /** @var ConstraintViolationInterface $violation */
28
            $errors[$violation->getPropertyPath()] = [
29
                'message'       => $violation->getMessage(),
30
                'code'          => $violation->getCode(),
31
                'root'          => $violation->getRoot(),
32
                'invalid_value' => $violation->getInvalidValue(),
33
            ];
34
        }
35
36
        return new static(
37
            'Invalid data submitted for entity: ' . PHP_EOL .
38
            Yaml::dump($errors)
39
        );
40
    }
41
42
}
43