Passed
Push — master ( 1fa5c8...3c4917 )
by Gabriel
02:55
created

VariableMapper::map()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 25
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.439
c 0
b 0
f 0
ccs 17
cts 17
cp 1
cc 6
eloc 21
nc 6
nop 2
crap 6
1
<?php
2
3
namespace Waredesk\Mappers;
4
5
use Waredesk\Mapper;
6
use Waredesk\Mappers\Variable\ElementsMapper;
7
use Waredesk\Models\Variable;
8
use DateTime;
9
10
class VariableMapper extends Mapper
11
{
12 2
    public function map(Variable $variable, array $data): Variable
13
    {
14 2
        $finalData = [];
15 2
        foreach ($data as $key => $value) {
16
            switch ($key) {
17 2
                case 'quantity':
18
                    $finalData['quantity'] = (int)$value;
19
                    break;
20 2
                case 'elements':
21 2
                    $finalData['elements'] = (new ElementsMapper())->map($variable->getElements(), $value);
22 2
                    break;
23 2
                case 'creation':
24 2
                    $finalData['creation'] = new DateTime($value);
25 2
                    break;
26 2
                case 'modification':
27 2
                    $finalData['modification'] = new DateTime($value);
28 2
                    break;
29
                default:
30 2
                    $finalData[$key] = $value;
31 2
                    break;
32
            }
33
        }
34 2
        $variable->reset($finalData);
35 2
        return $variable;
36
    }
37
}
38