Test Failed
Push — main ( 450f80...a11e57 )
by Fractal
02:32
created

BuiltinPropertyMapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A canMap() 0 3 2
A __construct() 0 3 1
A map() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\RequestMapper\PropertyMapper\Mapper;
6
7
use FRZB\Component\DependencyInjection\Attribute\AsService;
8
use FRZB\Component\DependencyInjection\Attribute\AsTagged;
9
use FRZB\Component\PhpDocReader\Reader\ReaderInterface as PhpDocReader;
10
use FRZB\Component\RequestMapper\Helper\ConstraintsHelper;
11
use FRZB\Component\RequestMapper\Helper\PropertyHelper;
12
13
#[AsService, AsTagged(PropertyMapperInterface::class, priority: 1)]
14
final class BuiltinPropertyMapper implements PropertyMapperInterface
15
{
16
    public function __construct(
17
        private readonly PhpDocReader $reader,
18
    ) {
19
    }
20
21
    public function map(\ReflectionProperty $property, mixed $value): array
22
    {
23
        return [PropertyHelper::getName($property) => PropertyHelper::getTypeName($property)];
24
    }
25
26
    public function canMap(\ReflectionProperty $property): bool
27
    {
28
        return !ConstraintsHelper::hasArrayTypeAttribute($property) && !ConstraintsHelper::hasArrayDocBlock($property, $this->reader);
29
    }
30
}
31