Completed
Push — master ( 134b2d...f2c57a )
by Gabriel
02:40
created

CategoryMapper::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;
4
5
use Waredesk\Mapper;
6
use Waredesk\Models\Category;
7
use DateTime;
8
9 View Code Duplication
class CategoryMapper 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(Category $category, array $data): Category
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
        $category->reset($finalData);
28 2
        return $category;
29
    }
30
}
31