Code Duplication    Length = 22-22 lines in 3 locations

src/Mappers/CodeMapper.php 1 location

@@ 12-33 (lines=22) @@
9
10
class CodeMapper
11
{
12
    public function map(Code $code, array $data): Code
13
    {
14
        $finalData = [];
15
        foreach ($data as $key => $value) {
16
            switch ($key) {
17
                case 'elements':
18
                    $finalData['elements'] = (new ElementsMapper())->map(new Elements(), $value);
19
                    break;
20
                case 'creation':
21
                    $finalData['creation'] = new DateTime($value);
22
                    break;
23
                case 'modification':
24
                    $finalData['modification'] = new DateTime($value);
25
                    break;
26
                default:
27
                    $finalData[$key] = $value;
28
                    break;
29
            }
30
        }
31
        $code->reset($finalData);
32
        return $code;
33
    }
34
}
35

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

@@ 11-32 (lines=22) @@
8
9
class CodeMapper
10
{
11
    public function map(Code $code, $data): Code
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

src/Mappers/ProductMapper.php 1 location

@@ 12-33 (lines=22) @@
9
10
class ProductMapper
11
{
12
    public function map(Product $product, array $data): Product
13
    {
14
        $finalData = [];
15
        foreach ($data as $key => $value) {
16
            switch ($key) {
17
                case 'variants':
18
                    $finalData['variants'] = (new VariantsMapper())->map(new Variants(), $value);
19
                    break;
20
                case 'creation':
21
                    $finalData['creation'] = new DateTime($value);
22
                    break;
23
                case 'modification':
24
                    $finalData['modification'] = new DateTime($value);
25
                    break;
26
                default:
27
                    $finalData[$key] = $value;
28
                    break;
29
            }
30
        }
31
        $product->reset($finalData);
32
        return $product;
33
    }
34
}
35