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

CodeMapper::map()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 22
Code Lines 18

Duplication

Lines 22
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 22
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\Collections\Products\Variants\Codes\Elements;
7
use Waredesk\Models\Product\Variant\Code;
8
9
class CodeMapper
10
{
11 View Code Duplication
    public function map(Code $code, $data): Code
0 ignored issues
show
Duplication introduced by
This method 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...
12
    {
13
        $finalData = [];
14
        foreach ($data as $key => $value) {
15
            switch ($key) {
16
                case 'elements':
17
                    $finalData['elements'] = (new ElementsMapper())->map(new Elements(), $value);
18
                    break;
19
                case 'creation':
20
                    $finalData['creation'] = new DateTime($value);
21
                    break;
22
                case 'modification':
23
                    $finalData['modification'] = new DateTime($value);
24
                    break;
25
                default:
26
                    $finalData[$key] = $value;
27
                    break;
28
            }
29
        }
30
        $code->reset($finalData);
31
        return $code;
32
    }
33
}
34