ItemMapper::map()   C
last analyzed

Complexity

Conditions 7
Paths 7

Size

Total Lines 28
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 22
cts 22
cp 1
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 24
nc 7
nop 2
crap 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