Completed
Push — master ( e6ba08...9dbf89 )
by Gabriel
02:34
created

PriceMapper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 25
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B map() 0 22 5
1
<?php
2
3
namespace Waredesk\Mappers\Product\Variant;
4
5
use DateTime;
6
use Waredesk\Models\Product\Variant\Price;
7
8
class PriceMapper
9
{
10
    public function map(Price $price, $data): Price
11
    {
12
        $finalData = [];
13
        foreach ($data as $key => $value) {
14
            switch ($key) {
15
                case 'price':
16
                    $finalData['price'] = (int)$value;
17
                    break;
18
                case 'creation':
19
                    $finalData['creation'] = new DateTime($value);
20
                    break;
21
                case 'modification':
22
                    $finalData['modification'] = new DateTime($value);
23
                    break;
24
                default:
25
                    $finalData[$key] = $value;
26
                    break;
27
            }
28
        }
29
        $price->reset($finalData);
30
        return $price;
31
    }
32
}
33