Passed
Push — master ( a35b5f...c35142 )
by Vitor de
02:29
created

Manager::map()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
ccs 15
cts 15
cp 1
rs 8.8571
cc 5
eloc 11
nc 3
nop 2
crap 5
1
<?php
2
3
namespace GFG\Mapper\Data;
4
5
class Manager
6
{
7
    private $mapper;
8
    private $factory;
9
10 1
    public function __construct(
11
        MapperInterface $mapper,
12
        MapperFactory $factory
13
    ) {
14 1
        $this->mapper    = $mapper;
15 1
        $this->factory   = $factory;
16 1
    }
17
18 1
    public function map(array &$data, array $structure)
19
    {
20 1
        foreach ($structure as $key => $value) {
21
22 1
            $keyData = &$data[$key];
23
24 1
            if (!isset($value['prefix'])) {
25 1
                $this->map($keyData, $value);
26 1
            } else {
27 1
                foreach ((array) $value['type'] as $type) {
28 1
                    $type = $this->factory->create($type, $this->mapper, [
29 1
                        'prefix' => $value['prefix'],
30 1
                        'use'    => isset($value['use']) ? $value['use'] : ''
31 1
                    ]);
32 1
                    $type->run($keyData);
33 1
                }
34
            }
35 1
        }
36 1
    }
37
}
38