ApiValidationError   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 87.5%

Importance

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

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 8
    public function __construct($errorData)
17
    {
18
        /** @var string[] $errors */
19 8
        $errors = [];
20
21 8
        if ($errorData instanceof FormInterface) {
22
            /** @var FormError $error */
23 8
            foreach ($errorData->getErrors(true) as $error) {
24 8
                $errors[] = $error->getMessage();
25
            }
26
        } else {
27
            $errors = (array) $errorData;
28
        }
29
30 8
        parent::__construct($errors, Response::HTTP_BAD_REQUEST);
31 8
    }
32
}
33