Completed
Push — master ( ab94e9...fa2f9e )
by Gabriel
02:21
created

VariantMapper   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 7
dl 0
loc 56
ccs 48
cts 48
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C map() 0 53 17
1
<?php
2
3
namespace Waredesk\Mappers\Product;
4
5
use DateTime;
6
use Waredesk\Collections\Products\Variants\Codes;
7
use Waredesk\Collections\Products\Variants\Options;
8
use Waredesk\Collections\Products\Variants\Prices;
9
use Waredesk\Mappers\Product\Variant\CodesMapper;
10
use Waredesk\Mappers\Product\Variant\OptionsMapper;
11
use Waredesk\Mappers\Product\Variant\PricesMapper;
12
use Waredesk\Models\Product\Variant;
13
14
class VariantMapper
15
{
16 1
    public function map(Variant $variant, $data): Variant
17
    {
18 1
        foreach ($data as $key => $value) {
19
            switch ($key) {
20 1
                case 'id':
21 1
                    $variant->setId((int)$value);
22 1
                    break;
23 1
                case 'images':
24 1
                    $variant->setImages($value);
25 1
                    break;
26 1
                case 'options':
27 1
                    $variant->setOptions((new OptionsMapper())->map(new Options(), $value));
28 1
                    break;
29 1
                case 'codes':
30 1
                    $variant->setCodes((new CodesMapper())->map(new Codes(), $value));
31 1
                    break;
32 1
                case 'prices':
33 1
                    $variant->setPrices((new PricesMapper())->map(new Prices(), $value));
34 1
                    break;
35 1
                case 'description':
36 1
                    $variant->setDescription($value);
37 1
                    break;
38 1
                case 'notes':
39 1
                    $variant->setNotes($value);
40 1
                    break;
41 1
                case 'weight_unit':
42 1
                    $variant->setWeightUnit($value);
43 1
                    break;
44 1
                case 'length_unit':
45 1
                    $variant->setLengthUnit($value);
46 1
                    break;
47 1
                case 'weight':
48 1
                    $variant->setWeight((float)$value);
49 1
                    break;
50 1
                case 'height':
51 1
                    $variant->setHeight((float)$value);
52 1
                    break;
53 1
                case 'depth':
54 1
                    $variant->setDepth((float)$value);
55 1
                    break;
56 1
                case 'width':
57 1
                    $variant->setWidth((float)$value);
58 1
                    break;
59 1
                case 'creation_datetime':
60 1
                    $variant->setCreationDatetime(new DateTime($value));
61 1
                    break;
62 1
                case 'modification_datetime':
63 1
                    $variant->setModificationDatetime(new DateTime($value));
64 1
                    break;
65
            }
66
        }
67 1
        return $variant;
68
    }
69
}
70