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

ApiValidationError::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 9.4285
c 3
b 0
f 0
cc 3
eloc 8
nc 2
nop 1
crap 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