Passed
Push — develop ( 78e2d5...9c7a10 )
by Laurent
02:42 queued 01:21
created

SupplierHandler::deserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 16
nc 1
nop 2
dl 0
loc 18
rs 9.7333
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the G.L.S.R. Apps package.
7
 *
8
 * (c) Dev-Int Création <[email protected]>.
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Administration\Infrastructure\Supplier\Serializer\Handler;
15
16
use Administration\Application\Supplier\ReadModel\Supplier;
17
use JMS\Serializer\GraphNavigator;
0 ignored issues
show
Bug introduced by
The type JMS\Serializer\GraphNavigator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use JMS\Serializer\Handler\SubscribingHandlerInterface;
0 ignored issues
show
Bug introduced by
The type JMS\Serializer\Handler\SubscribingHandlerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use JMS\Serializer\JsonDeserializationVisitor;
0 ignored issues
show
Bug introduced by
The type JMS\Serializer\JsonDeserializationVisitor was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use JMS\Serializer\JsonSerializationVisitor;
0 ignored issues
show
Bug introduced by
The type JMS\Serializer\JsonSerializationVisitor was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
22
class SupplierHandler implements SubscribingHandlerInterface
23
{
24
    public static function getSubscribingMethods(): array
25
    {
26
        return [
27
            [
28
                'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
29
                'format' => 'json',
30
                'type' => Supplier::class,
31
                'method' => 'serialize',
32
            ],
33
            [
34
                'direction' => GraphNavigator::DIRECTION_DESERIALIZATION,
35
                'format' => 'json',
36
                'type' => Supplier::class,
37
                'method' => 'deserialize',
38
            ],
39
        ];
40
    }
41
42
    public function serialize(JsonSerializationVisitor $visitor, Supplier $supplier, array $type): array
43
    {
44
        $data = [
45
            'uuid' => $supplier->uuid(),
46
            'name' => $supplier->name(),
47
            'address' => $supplier->address(),
48
            'zipCode' => $supplier->zipCode(),
49
            'town' => $supplier->town(),
50
            'country' => $supplier->country(),
51
            'phone' => $supplier->phone(),
52
            'facsimile' => $supplier->facsimile(),
53
            'email' => $supplier->email(),
54
            'contact' => $supplier->contact(),
55
            'cellphone' => $supplier->cellphone(),
56
            'familyLog' => $supplier->familyLog(),
57
            'delayDelivery' => $supplier->delayDelivery(),
58
            'orderDays' => $supplier->orderDays(),
59
            'slug' => $supplier->slug(),
60
        ];
61
62
        return $visitor->visitArray($data, $type);
63
    }
64
65
    public function deserialize(JsonDeserializationVisitor $visitor, array $data): Supplier
66
    {
67
        return new Supplier(
68
            $data['uuid'],
69
            $data['name'],
70
            $data['address'],
71
            $data['zipCode'],
72
            $data['town'],
73
            $data['country'],
74
            $data['phone'],
75
            $data['facsimile'],
76
            $data['email'],
77
            $data['contact'],
78
            $data['cellphone'],
79
            $data['familyLog'],
80
            $data['delayDelivery'],
81
            $data['orderDays'],
82
            $data['slug'],
83
        );
84
    }
85
}
86