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

ParamConverter::equals()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 3
rs 10
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