Passed
Pull Request — main (#2)
by Fractal
02:50
created

ConverterData::getSerializerContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\RequestMapper\Data;
6
7
use FRZB\Component\RequestMapper\Attribute\ParamConverter;
8
use JetBrains\PhpStorm\Immutable;
9
use JetBrains\PhpStorm\Pure;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
12
13
#[Immutable]
14
final class ConverterData
15
{
16
    private const DEFAULT_CONTEXT = [AbstractObjectNormalizer::DISABLE_TYPE_ENFORCEMENT => true];
17
18
    private Request $request;
19
    private ParamConverter $attribute;
20
21 25
    public function __construct(Request $request, ParamConverter $attribute)
22
    {
23 25
        $this->request = $request;
24 25
        $this->attribute = $attribute;
25 25
    }
26
27
    public function getRequest(): Request
28
    {
29
        return $this->request;
30
    }
31
32 19
    public function getRequestParameters(): array
33
    {
34 19
        return $this->request->request->all();
35
    }
36
37 19
    #[Pure]
38
    public function getParameterClass(): ?string
39
    {
40 19
        return $this->attribute->getParameterClass();
41
    }
42
43 16
    #[Pure]
44
    public function isValidationNeeded(): bool
45
    {
46 16
        return $this->attribute->isValidationNeeded();
47
    }
48
49 14
    #[Pure]
50
    public function getSerializerContext(): array
51
    {
52 14
        return array_merge($this->attribute->getSerializerContext(), self::DEFAULT_CONTEXT);
53
    }
54
55 16
    #[Pure]
56
    public function getValidationGroups(): array
57
    {
58 16
        return $this->attribute->getValidationGroups();
59
    }
60
}
61