Test Failed
Push — main ( 8bbfd5...5b42e4 )
by Fractal
03:27
created

DocBlockArrayPropertyMapper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A map() 0 4 1
A canMap() 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: 2)]
14
final class DocBlockArrayPropertyMapper 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 [
24
            PropertyHelper::getName($property) => array_map(fn () => PropertyHelper::getTypeFromDocBlock($property, $this->reader), range(0, \count($value))),
25
        ];
26
    }
27
28
    public function canMap(\ReflectionProperty $property): bool
29
    {
30
        return ConstraintsHelper::hasArrayTypeAttribute($property);
31
    }
32
}
33