Passed
Push — master ( 1b9891...006f9a )
by Petr
04:14
created

ApiValidationError::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 0
loc 16
c 3
b 0
f 0
rs 9.4285
ccs 7
cts 8
cp 0.875
cc 3
eloc 8
nc 2
nop 1
crap 3.0175
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 7
            foreach ($errorData->getErrors(true) as $error) {
24 7
                $errors[] = $error->getMessage();
25
            }
26
        } else {
27
            $errors = (array) $errorData;
28
        }
29
30 7
        parent::__construct($errors, Response::HTTP_BAD_REQUEST);
31 7
    }
32
}
33