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

ApiValidationError   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 22
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 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