ParametersMapper   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A map() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Routing\Parameter;
6
7
use Symfony\Component\PropertyAccess\PropertyAccess;
8
9
class ParametersMapper
10
{
11
    /**
12
     * Map a list of parameters to properties of the given object.
13
     *
14
     * @param object $data Data use to fill parameters
15
     * @param array<int, string> $routeParameters The list of the parameter names to map
16
     *
17
     * @return array<string, string> Mapped parameters
18
     */
19
    public function map(object $data, array $routeParameters = []): array
20
    {
21
        $accessor = PropertyAccess::createPropertyAccessor();
22
        $mappedRouteParameters = [];
23
24
        foreach ($routeParameters as $parameter) {
25
            $mappedRouteParameters[$parameter] = $accessor->getValue($data, (string) $parameter);
26
        }
27
28
        return $mappedRouteParameters;
29
    }
30
}
31