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

VariableMapper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 28
rs 10
c 0
b 0
f 0
ccs 17
cts 17
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B map() 0 25 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