Completed
Push — master ( 743367...2eb0ee )
by Gabriel
06:30
created

AttributeMapper::map()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 15

Duplication

Lines 19
Ratio 100 %

Code Coverage

Tests 13
CRAP Score 4

Importance

Changes 0
Metric Value
dl 19
loc 19
ccs 13
cts 13
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 15
nc 4
nop 2
crap 4
1
<?php
2
3
namespace Waredesk\Mappers\Inventory\Item;
4
5
use DateTime;
6
use Waredesk\Mapper;
7
use Waredesk\Models\Inventory\Item\Attribute;
8
9 View Code Duplication
class AttributeMapper extends Mapper
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11 2
    public function map(Attribute $attribute, array $data): Attribute
12
    {
13 2
        $finalData = [];
14 2
        foreach ($data as $key => $value) {
15
            switch ($key) {
16 2
                case 'creation':
17 2
                    $finalData['creation'] = new DateTime($value);
18 2
                    break;
19 2
                case 'modification':
20 2
                    $finalData['modification'] = new DateTime($value);
21 2
                    break;
22
                default:
23 2
                    $finalData[$key] = $value;
24 2
                    break;
25
            }
26
        }
27 2
        $attribute->reset($finalData);
28 2
        return $attribute;
29
    }
30
}
31