Completed
Push — master ( b2620d...cacd0e )
by Gabriel
02:27
created

ProductMapper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 28
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B map() 0 25 6
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 3
    public function map(Product $product, array $data): Product
13
    {
14 3
        $finalData = [];
15 3
        foreach ($data as $key => $value) {
16
            switch ($key) {
17 3
                case 'id':
18 3
                    $finalData['id'] = (int)$value;
19 3
                    break;
20 3
                case 'variants':
21 3
                    $finalData['variants'] = (new VariantsMapper())->map(new Variants(), $value);
22 3
                    break;
23 3
                case 'creation_datetime':
24 3
                    $finalData['creation_datetime'] = new DateTime($value);
25 3
                    break;
26 3
                case 'modification_datetime':
27 3
                    $finalData['modification_datetime'] = new DateTime($value);
28 3
                    break;
29
                default:
30 3
                    $finalData[$key] = $value;
31 3
                    break;
32
            }
33
        }
34 3
        $product->reset($finalData);
35 3
        return $product;
36
    }
37
}
38