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

ProductMapper   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 35
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
D map() 0 32 10
1
<?php
2
3
namespace Waredesk\Mappers;
4
5
use Waredesk\Collections\Products\Variants;
6
use Waredesk\Mappers\Product\VariantsMapper;
7
use Waredesk\Models\Product;
8
use DateTime;
9
10
class ProductMapper
11
{
12 1
    public function map(Product $product, array $data): Product
13
    {
14 1
        foreach ($data as $key => $value) {
15
            switch ($key) {
16 1
                case 'id':
17 1
                    $product->setId((int)$value);
18 1
                    break;
19 1
                case 'images':
20 1
                    $product->setImages($value);
21 1
                    break;
22 1
                case 'variants':
23 1
                    $product->setVariants((new VariantsMapper())->map(new Variants(), $value));
24 1
                    break;
25 1
                case 'name':
26 1
                    $product->setName($value);
27 1
                    break;
28 1
                case 'description':
29 1
                    $product->setDescription($value);
30 1
                    break;
31 1
                case 'notes':
32 1
                    $product->setNotes($value);
33 1
                    break;
34 1
                case 'creation_datetime':
35 1
                    $product->setCreationDatetime(new DateTime($value));
36 1
                    break;
37 1
                case 'modification_datetime':
38 1
                    $product->setModificationDatetime(new DateTime($value));
39 1
                    break;
40
            }
41
        }
42 1
        return $product;
43
    }
44
}
45