Passed
Push — master ( eabfa3...2db6fa )
by Petr
04:00
created

ApiValidationError   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 21
ccs 8
cts 8
cp 1
rs 10
c 3
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 3
1
<?php
2
3
namespace AppBundle\Response;
4
5
use Symfony\Component\Form\FormError;
6
use Symfony\Component\Form\FormInterface;
7
use Symfony\Component\HttpFoundation\Response;
8
9
/**
10
 * @author Vehsamrak
11
 */
12
class ApiValidationError extends ApiError
13
{
14
15
    /** {@inheritDoc} */
16 7
    public function __construct($errorData)
17
    {
18
        /** @var string[] $errors */
19 7
        $errors = [];
20
21 7
        if ($errorData instanceof FormInterface) {
22
            /** @var FormError $error */
23 6
            foreach ($errorData->getErrors(true) as $error) {
24 6
                $errors[] = $error->getMessage();
25
            }
26
        } else {
27 1
            $errors = (array) $errorData;
28
        }
29
30 7
        parent::__construct($errors, Response::HTTP_BAD_REQUEST);
31 7
    }
32
}
33