Passed
Push — main ( ee7b7b...414146 )
by Fractal
02:40
created

ParamConverter   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 49
ccs 18
cts 18
cp 1
rs 10
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getParameterClass() 0 3 1
A isValidationNeeded() 0 3 1
A getSerializerContext() 0 3 1
A getParameterName() 0 3 1
A __construct() 0 8 1
A equals() 0 7 3
A getValidationGroups() 0 5 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\RequestMapper\Attribute;
6
7
use JetBrains\PhpStorm\Pure;
8
9
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD | \Attribute::TARGET_FUNCTION)]
10
final class ParamConverter
11
{
12
    public const DEFAULT_VALIDATION_GROUP = 'Default';
13
14 23
    public function __construct(
15
        private ?string $parameterClass = null,
16
        private ?string $parameterName = null,
17
        private bool $isValidationNeeded = true,
18
        private array $serializerContext = [],
19
        private array $validationGroups = [],
20
        private bool $useDefaultValidationGroup = true,
21
    ) {
22 23
    }
23
24 26
    public function getParameterClass(): ?string
25
    {
26 26
        return $this->parameterClass;
27
    }
28
29 21
    public function getParameterName(): ?string
30
    {
31 21
        return $this->parameterName;
32
    }
33
34 14
    public function isValidationNeeded(): bool
35
    {
36 14
        return $this->isValidationNeeded;
37
    }
38
39 12
    public function getSerializerContext(): array
40
    {
41 12
        return $this->serializerContext;
42
    }
43
44 15
    public function getValidationGroups(): array
45
    {
46 15
        return $this->useDefaultValidationGroup
47 15
            ? array_merge($this->validationGroups, [self::DEFAULT_VALIDATION_GROUP])
48 15
            : $this->validationGroups;
49
    }
50
51 11
    #[Pure]
52
    public function equals(object $object): bool
53
    {
54
        return match (true) {
55 11
            $object instanceof \ReflectionParameter => $object->getType()?->getName() === $this->parameterClass && $object->getName() === $this->parameterName,
56 4
            $object instanceof self => $object->getParameterClass() === $this->parameterClass && $object->getParameterName() === $this->parameterName,
57 11
            default => false
58
        };
59
    }
60
}
61