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

DocBlockArrayPropertyMapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

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