VariableMapper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B map() 0 25 6
1
<?php
2
3
namespace Waredesk\Mappers;
4
5
use Waredesk\Collections\Variables\Elements;
6
use Waredesk\Mapper;
7
use Waredesk\Mappers\Variable\ElementsMapper;
8
use Waredesk\Models\Variable;
9
use DateTime;
10
11
class VariableMapper extends Mapper
12
{
13 4
    public function map(Variable $variable, array $data): Variable
14
    {
15 4
        $finalData = [];
16 4
        foreach ($data as $key => $value) {
17
            switch ($key) {
18 4
                case 'quantity':
19
                    $finalData['quantity'] = (int)$value;
20
                    break;
21 4
                case 'elements':
22 4
                    $finalData['elements'] = (new ElementsMapper())->map(new Elements(), $value);
23 4
                    break;
24 4
                case 'creation':
25 4
                    $finalData['creation'] = new DateTime($value);
26 4
                    break;
27 4
                case 'modification':
28 4
                    $finalData['modification'] = new DateTime($value);
29 4
                    break;
30
                default:
31 4
                    $finalData[$key] = $value;
32 4
                    break;
33
            }
34
        }
35 4
        $variable->reset($finalData);
36 4
        return $variable;
37
    }
38
}
39