Passed
Push — develop ( 888544...81b1bd )
by Laurent
02:19
created

CompanyHandler::getSubscribingMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 14
rs 9.9666
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\Company\Serializer\Handler;
15
16
use Administration\Domain\Company\Model\Company;
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 CompanyHandler implements SubscribingHandlerInterface
23
{
24
    public static function getSubscribingMethods(): array
25
    {
26
        return [
27
            [
28
                'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
29
                'format' => 'json',
30
                'type' => Company::class,
31
                'method' => 'serialize',
32
            ],
33
            [
34
                'direction' => GraphNavigator::DIRECTION_DESERIALIZATION,
35
                'format' => 'json',
36
                'type' => Company::class,
37
                'method' => 'deserialize',
38
            ],
39
        ];
40
    }
41
42
    public function serialize(JsonSerializationVisitor $visitor, Company $company, array $type): array
43
    {
44
        $data = [
45
            'uuid' => $company->uuid(),
46
            'name' => $company->name(),
47
            'address' => $company->address(),
48
            'zipCode' => $company->zipCode(),
49
            'town' => $company->town(),
50
            'country' => $company->country(),
51
            'phone' => $company->phone(),
52
            'facsimile' => $company->facsimile(),
53
            'email' => $company->email(),
54
            'contact' => $company->contact(),
55
            'cellphone' => $company->cellphone(),
56
            'slug' => $company->slug(),
57
        ];
58
59
        return $visitor->visitArray($data, $type);
60
    }
61
62
    public function deserialize(JsonDeserializationVisitor $visitor, array $data): Company
63
    {
64
        return new Company(
65
            $data['uuid'],
66
            $data['name'],
67
            $data['address'],
68
            $data['zipCode'],
69
            $data['town'],
70
            $data['country'],
71
            $data['phone'],
72
            $data['facsimile'],
73
            $data['email'],
74
            $data['contact'],
75
            $data['cellphone'],
76
        );
77
    }
78
}
79