Test Failed
Push — main ( 6e42c7...fc4189 )
by Fractal
02:46
created

ArrayAsAttributePropertyMapper   A

Complexity

Total Complexity 3

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 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A canMap() 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\RequestMapper\Helper\PropertyHelper;
10
use FRZB\Component\RequestMapper\TypeExtractor\Extractor\ArrayTypeAttributeExtractor;
11
12
#[AsService, AsTagged(PropertyMapperInterface::class, priority: 3)]
13
class ArrayAsAttributePropertyMapper implements PropertyMapperInterface
14
{
15
    public function __construct(
16
        private readonly ArrayTypeAttributeExtractor $extractor,
17
    ) {
18
    }
19
20
    public function map(\ReflectionProperty $property, mixed $value): array
21
    {
22
        return [PropertyHelper::getName($property) => array_map(static fn () => $this->extractor->extract($property), range(0, \count($value)))];
23
    }
24
25
    public function canMap(\ReflectionProperty $property): bool
26
    {
27
        return $this->extractor->canExtract($property);
28
    }
29
}
30