Completed
Push — master ( 079a45...f661f8 )
by Alexey
03:08 queued 11s
created

QueryObjectValueResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 3 1
A serialize() 0 8 1
A supports() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nelexa\RequestDtoBundle\ArgumentResolver;
6
7
use Nelexa\RequestDtoBundle\Dto\QueryObjectInterface;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
10
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
11
12
class QueryObjectValueResolver extends AbstractObjectValueResolver
13
{
14 15
    public function supports(Request $request, ArgumentMetadata $argument): bool
15
    {
16 15
        return is_a($argument->getType(), QueryObjectInterface::class, true);
17
    }
18
19 14
    protected function serialize(Request $request, ArgumentMetadata $argument, string $format): object
20
    {
21 14
        return $this->serializer->denormalize(
22 14
            $this->getData($request),
23 14
            $argument->getType(),
24
            $format,
25
            [
26 14
                AbstractObjectNormalizer::DISABLE_TYPE_ENFORCEMENT => true,
27
            ]
28
        );
29
    }
30
31 9
    protected function getData(Request $request): array
32
    {
33 9
        return $request->query->all();
34
    }
35
}
36