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

PriceMapper::map()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 22
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 0
cts 16
cp 0
rs 8.6737
c 0
b 0
f 0
cc 5
eloc 18
nc 5
nop 2
crap 30
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