ItemMapper   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 6
dl 0
loc 31
ccs 22
cts 22
cp 1
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\Attributes;
7
use Waredesk\Mapper;
8
use DateTime;
9
use Waredesk\Mappers\Inventory\Item\ActivitiesMapper;
10
use Waredesk\Mappers\Inventory\Item\AttributesMapper;
11
use Waredesk\Models\Inventory\Item;
12
13
class ItemMapper extends Mapper
14
{
15 3
    public function map(Item $item, array $data): Item
16
    {
17 3
        $finalData = [];
18 3
        foreach ($data as $key => $value) {
19
            switch ($key) {
20 3
                case 'activities':
21 3
                    $finalData['activities'] = (new ActivitiesMapper())->map(new Activities(), $value);
22 3
                    break;
23 3
                case 'attributes':
24 3
                    $finalData['attributes'] = (new AttributesMapper())->map(new Attributes(), $value);
25 3
                    break;
26 3
                case 'in_stock':
27 3
                    $finalData['variants'] = (bool)$value;
28 3
                    break;
29 3
                case 'creation':
30 3
                    $finalData['creation'] = new DateTime($value);
31 3
                    break;
32 3
                case 'modification':
33 3
                    $finalData['modification'] = new DateTime($value);
34 3
                    break;
35
                default:
36 3
                    $finalData[$key] = $value;
37 3
                    break;
38
            }
39
        }
40 3
        $item->reset($finalData);
41 3
        return $item;
42
    }
43
}
44