RequestDtoControllerArgumentListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 7
c 1
b 0
f 1
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A onControllerArguments() 0 12 3
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 26
    public function onControllerArguments(ControllerArgumentsEvent $event): void
15
    {
16 26
        $request = $event->getRequest();
17
18 26
        $key = ConstraintViolationListValueResolver::REQUEST_ATTR_KEY;
19
20 26
        if ($request->attributes->has($key)) {
21
            /** @var ConstraintViolationList $violationList */
22 8
            $violationList = $request->attributes->get($key);
23
24 8
            if ($violationList->count() > 0) {
25 4
                throw new RequestDtoValidationException($violationList, 'Bad Request');
26
            }
27
        }
28 22
    }
29
}
30