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

Manager   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 33
ccs 19
cts 19
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B map() 0 19 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