Completed
Push — master ( d7ece8...443c1d )
by Valentyn
12:07
created

BaseRequest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getErrorResponse() 0 14 1
1
<?php
2
3
namespace App\Request;
4
5
use Fesor\RequestObject\RequestObject;
6
use Symfony\Component\HttpFoundation\JsonResponse;
7
use Fesor\RequestObject\ErrorResponseProvider;
8
use Symfony\Component\Validator\ConstraintViolationListInterface;
9
use Symfony\Component\Validator\ConstraintViolation;
10
use Symfony\Component\PropertyAccess\PropertyAccess;
11
12
class BaseRequest extends RequestObject implements ErrorResponseProvider
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function getErrorResponse(ConstraintViolationListInterface $errors)
18
    {
19
        $propertyAccessor = PropertyAccess::createPropertyAccessor();
20
21
        return new JsonResponse([
22
            'message' => 'Please check your data',
23
            'errors' => array_map(function (ConstraintViolation $violation) use ($propertyAccessor) {
24
                return [
25
                    'path' => $violation->getPropertyPath(),
26
                    'message' => $violation->getMessage(),
27
                ];
28
            }, iterator_to_array($errors)),
29
        ], 400);
30
    }
31
}