Passed
Push — master ( 4ca145...e39a6b )
by Jakub
02:24
created

ParamCollector   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 32
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A collect() 0 11 1
A addMapper() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Eps\Req2CmdBundle\Params\ParamCollector;
5
6
use Eps\Req2CmdBundle\Params\ParameterMapper\ParamMapperInterface;
7
use Symfony\Component\HttpFoundation\Request;
8
9
class ParamCollector implements ParamCollectorInterface
10
{
11
    /**
12
     * @var ParamMapperInterface[]
13
     */
14
    private $mappers;
15
16
    public function __construct(array $mappers)
17
    {
18
        $this->mappers = [];
19
        foreach ($mappers as $mapper) {
20
            $this->addMapper($mapper);
21
        }
22
    }
23
24
    public function collect(Request $request, array $propsMap): array
25
    {
26
        return array_reduce(
27
            $this->mappers,
28
            function (array $carry, ParamMapperInterface $mapper) use ($request, $propsMap) {
29
                $carry = array_merge($carry, $mapper->map($request, $propsMap));
30
                return $carry;
31
            },
32
            []
33
        );
34
    }
35
36
    private function addMapper(ParamMapperInterface $mapper): void
37
    {
38
        $this->mappers[] = $mapper;
39
    }
40
}
41