Code Duplication    Length = 22-22 lines in 3 locations

src/Mappers/CategoryMapper.php 1 location

@@ 9-30 (lines=22) @@
6
use Waredesk\Models\Category;
7
use DateTime;
8
9
class CategoryMapper extends Mapper
10
{
11
    public function map(Category $category, array $data): Category
12
    {
13
        $finalData = [];
14
        foreach ($data as $key => $value) {
15
            switch ($key) {
16
                case 'creation':
17
                    $finalData['creation'] = new DateTime($value);
18
                    break;
19
                case 'modification':
20
                    $finalData['modification'] = new DateTime($value);
21
                    break;
22
                default:
23
                    $finalData[$key] = $value;
24
                    break;
25
            }
26
        }
27
        $category->reset($finalData);
28
        return $category;
29
    }
30
}
31

src/Mappers/Product/Variant/AttributeMapper.php 1 location

@@ 9-30 (lines=22) @@
6
use Waredesk\Mapper;
7
use Waredesk\Models\Product\Variant\Attribute;
8
9
class AttributeMapper extends Mapper
10
{
11
    public function map(Attribute $attribute, $data): Attribute
12
    {
13
        $finalData = [];
14
        foreach ($data as $key => $value) {
15
            switch ($key) {
16
                case 'creation':
17
                    $finalData['creation'] = new DateTime($value);
18
                    break;
19
                case 'modification':
20
                    $finalData['modification'] = new DateTime($value);
21
                    break;
22
                default:
23
                    $finalData[$key] = $value;
24
                    break;
25
            }
26
        }
27
        $attribute->reset($finalData);
28
        return $attribute;
29
    }
30
}
31

src/Mappers/Product/Variant/Item/AttributeMapper.php 1 location

@@ 9-30 (lines=22) @@
6
use Waredesk\Mapper;
7
use Waredesk\Models\Product\Variant\Item\Attribute;
8
9
class AttributeMapper extends Mapper
10
{
11
    public function map(Attribute $attribute, $data): Attribute
12
    {
13
        $finalData = [];
14
        foreach ($data as $key => $value) {
15
            switch ($key) {
16
                case 'creation':
17
                    $finalData['creation'] = new DateTime($value);
18
                    break;
19
                case 'modification':
20
                    $finalData['modification'] = new DateTime($value);
21
                    break;
22
                default:
23
                    $finalData[$key] = $value;
24
                    break;
25
            }
26
        }
27
        $attribute->reset($finalData);
28
        return $attribute;
29
    }
30
}
31