Completed
Push — master ( 9dfe4a...9f73a9 )
by Alexey
03:27
created

onControllerArguments()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 6
c 1
b 0
f 1
nc 3
nop 1
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nelexa\RequestDtoBundle\EventListener;
6
7
use Nelexa\RequestDtoBundle\ArgumentResolver\ConstraintViolationListValueResolver;
8
use Nelexa\RequestDtoBundle\Exception\RequestDtoValidationException;
9
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
10
use Symfony\Component\Validator\ConstraintViolationList;
11
12
class RequestDtoControllerArgumentListener
13
{
14 19
    public function onControllerArguments(ControllerArgumentsEvent $event): void
15
    {
16 19
        $request = $event->getRequest();
17
18 19
        $key = ConstraintViolationListValueResolver::REQUEST_ATTR_KEY;
19
20 19
        if ($request->attributes->has($key)) {
21
            /** @var ConstraintViolationList $violationList */
22 6
            $violationList = $request->attributes->get($key);
23
24 6
            if ($violationList->count() > 0) {
25 3
                throw new RequestDtoValidationException($violationList, 'Bad Request');
26
            }
27
        }
28 16
    }
29
}
30