Passed
Push — master ( bd41e0...b80a23 )
by Gabriel
02:52
created

ItemMapper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 6
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C map() 0 28 7
1
<?php
2
3
namespace Waredesk\Mappers\Inventory;
4
5
use Waredesk\Collections\Inventory\Items\Activities;
6
use Waredesk\Collections\Inventory\Items\Codes;
7
use Waredesk\Mapper;
8
use DateTime;
9
use Waredesk\Mappers\Inventory\Item\ActivitiesMapper;
10
use Waredesk\Mappers\Inventory\Item\CodesMapper;
11
use Waredesk\Models\Inventory\Item;
12
13
class ItemMapper extends Mapper
14
{
15
    public function map(Item $item, array $data): Item
16
    {
17
        $finalData = [];
18
        foreach ($data as $key => $value) {
19
            switch ($key) {
20
                case 'activities':
21
                    $finalData['activities'] = (new ActivitiesMapper())->map(new Activities(), $value);
22
                    break;
23
                case 'codes':
24
                    $finalData['codes'] = (new CodesMapper())->map(new Codes(), $value);
25
                    break;
26
                case 'in_stock':
27
                    $finalData['variants'] = (bool)$value;
28
                    break;
29
                case 'creation':
30
                    $finalData['creation'] = new DateTime($value);
31
                    break;
32
                case 'modification':
33
                    $finalData['modification'] = new DateTime($value);
34
                    break;
35
                default:
36
                    $finalData[$key] = $value;
37
                    break;
38
            }
39
        }
40
        $item->reset($finalData);
41
        return $item;
42
    }
43
}
44