Passed
Push — master ( 63b45b...921011 )
by Petr
04:21
created

ApiValidationError::__construct()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 9.2
c 1
b 0
f 0
cc 4
eloc 9
nc 3
nop 1
crap 4
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 5
    public function __construct(FormInterface $form)
17
    {
18
        /** @var string[] $errors */
19 5
        $errors = [];
20
21
        /** @var FormError $error */
22 5
        foreach ($form->getErrors(true) as $error) {
23 5
            $parametersString = join(',', $error->getMessageParameters());
1 ignored issue
show
Bug introduced by
The method getMessageParameters() does not seem to exist on object<Symfony\Component\Form\FormErrorIterator>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24 5
            if (!$parametersString || in_array($parametersString, ['null', 'array'])) {
25 5
                $errors[] = $error->getMessage();
26
            } else {
27 5
                $errors[] = sprintf('%s - %s', $parametersString, $error->getMessage());
28
            }
29
        }
30
31 5
        parent::__construct($errors, Response::HTTP_BAD_REQUEST);
32 5
    }
33
}
34