Passed
Push — main ( c28c5f...2ef199 )
by Vasil
03:30
created

SpeedyModelDecorator   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Test Coverage

Coverage 40.35%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 46
c 1
b 0
f 0
dl 0
loc 139
ccs 23
cts 57
cp 0.4035
rs 10
wmc 15

14 Methods

Rating   Name   Duplication   Size   Complexity  
A findOffice() 0 8 1
A findCountry() 0 8 1
A findState() 0 8 1
A calculate() 0 8 1
A destination() 0 8 1
A findStreet() 0 8 1
A print() 0 3 1
A findComplex() 0 8 1
A __construct() 0 8 2
A track() 0 8 1
A getContractClient() 0 8 1
A findSite() 0 8 1
A createShipment() 0 8 1
A deserialize() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VasilDakov\Speedy;
6
7
use JMS\Serializer\SerializerInterface;
8
use VasilDakov\Speedy\Serializer\SerializerFactory;
9
use VasilDakov\Speedy\Service\Calculation\CalculationRequest;
10
use VasilDakov\Speedy\Service\Calculation\CalculationResponse;
11
use VasilDakov\Speedy\Service\Client\GetContractClientsRequest;
12
use VasilDakov\Speedy\Service\Client\GetContractClientsResponse;
13
use VasilDakov\Speedy\Service\Location\Complex\FindComplexRequest;
14
use VasilDakov\Speedy\Service\Location\Complex\FindComplexResponse;
15
use VasilDakov\Speedy\Service\Location\Country\FindCountryRequest;
16
use VasilDakov\Speedy\Service\Location\Country\FindCountryResponse;
17
use VasilDakov\Speedy\Service\Location\Office\FindOfficeRequest;
18
use VasilDakov\Speedy\Service\Location\Office\FindOfficeResponse;
19
use VasilDakov\Speedy\Service\Location\Site\FindSiteRequest;
20
use VasilDakov\Speedy\Service\Location\Site\FindSiteResponse;
21
use VasilDakov\Speedy\Service\Location\State\FindStateRequest;
22
use VasilDakov\Speedy\Service\Location\State\FindStateResponse;
23
use VasilDakov\Speedy\Service\Location\Street\FindStreetRequest;
24
use VasilDakov\Speedy\Service\Location\Street\FindStreetResponse;
25
use VasilDakov\Speedy\Service\Printing\PrintRequest;
26
use VasilDakov\Speedy\Service\Printing\PrintResponse;
27
use VasilDakov\Speedy\Service\Service\DestinationServicesRequest;
28
use VasilDakov\Speedy\Service\Service\DestinationServicesResponse;
29
use VasilDakov\Speedy\Service\Shipment\CreateShipmentRequest;
30
use VasilDakov\Speedy\Service\Shipment\CreateShipmentResponse;
31
use VasilDakov\Speedy\Service\Track\TrackRequest;
32
use VasilDakov\Speedy\Service\Track\TrackResponse;
33
34
final class SpeedyModelDecorator implements SpeedyInterface
35
{
36
    private SpeedyInterface $speedy;
37
38
    private SerializerInterface $serializer;
39
40 4
    public function __construct(SpeedyInterface $speedy, SerializerInterface $serializer = null)
41
    {
42 4
        $this->speedy = $speedy;
43
44 4
        if (null === $serializer) {
45 1
            $serializer = (new SerializerFactory())();
46
        }
47 4
        $this->serializer = $serializer;
48
    }
49
50 1
    public function getContractClient(GetContractClientsRequest $req): GetContractClientsResponse
51
    {
52 1
        $json = $this->speedy->getContractClient($req);
53
54
        /** @var GetContractClientsResponse $response */
55 1
        $response = $this->deserialize($json, GetContractClientsResponse::class);
0 ignored issues
show
Bug introduced by
It seems like $json can also be of type object; however, parameter $json of VasilDakov\Speedy\Speedy...ecorator::deserialize() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
        $response = $this->deserialize(/** @scrutinizer ignore-type */ $json, GetContractClientsResponse::class);
Loading history...
56
57 1
        return $response;
58
    }
59
60 1
    public function findCountry(FindCountryRequest $req): FindCountryResponse
61
    {
62 1
        $json = $this->speedy->findCountry($req);
63
64
        /** @var GetContractClientsResponse $response */
65 1
        $response = $this->deserialize(json: $json, type: FindCountryResponse::class);
0 ignored issues
show
Bug introduced by
It seems like $json can also be of type object; however, parameter $json of VasilDakov\Speedy\Speedy...ecorator::deserialize() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
        $response = $this->deserialize(/** @scrutinizer ignore-type */ json: $json, type: FindCountryResponse::class);
Loading history...
66
67 1
        return $response;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $response returns the type VasilDakov\Speedy\Servic...ContractClientsResponse which is incompatible with the type-hinted return VasilDakov\Speedy\Servic...try\FindCountryResponse.
Loading history...
68
    }
69
70
71 1
    public function findState(FindStateRequest $req): FindStateResponse
72
    {
73 1
        $json = $this->speedy->findState($req);
74
75
        /** @var FindStateResponse $response */
76 1
        $response = $this->deserialize(json: $json, type: FindStateResponse::class);
0 ignored issues
show
Bug introduced by
It seems like $json can also be of type object; however, parameter $json of VasilDakov\Speedy\Speedy...ecorator::deserialize() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

76
        $response = $this->deserialize(/** @scrutinizer ignore-type */ json: $json, type: FindStateResponse::class);
Loading history...
77
78 1
        return $response;
79
    }
80
81 3
    private function deserialize(string $json, string $type): object
82
    {
83 3
        return $this->serializer->deserialize(
84 3
            data: $json,
85 3
            type: $type,
86 3
            format: 'json'
87 3
        );
88
    }
89
90
    public function findSite(FindSiteRequest $req): FindSiteResponse
91
    {
92
        $json = $this->speedy->findSite($req);
93
94
        /** @var FindSiteResponse $response */
95
        $response = $this->deserialize(json: $json, type: FindSiteResponse::class);
0 ignored issues
show
Bug introduced by
It seems like $json can also be of type object; however, parameter $json of VasilDakov\Speedy\Speedy...ecorator::deserialize() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

95
        $response = $this->deserialize(/** @scrutinizer ignore-type */ json: $json, type: FindSiteResponse::class);
Loading history...
96
97
        return $response;
98
    }
99
100
    public function findOffice(FindOfficeRequest $req): FindOfficeResponse
101
    {
102
        $json = $this->speedy->findOffice($req);
103
104
        /** @var FindOfficeResponse $response */
105
        $response = $this->deserialize(json: $json, type: FindOfficeResponse::class);
0 ignored issues
show
Bug introduced by
It seems like $json can also be of type object; however, parameter $json of VasilDakov\Speedy\Speedy...ecorator::deserialize() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

105
        $response = $this->deserialize(/** @scrutinizer ignore-type */ json: $json, type: FindOfficeResponse::class);
Loading history...
106
107
        return $response;
108
    }
109
110
    public function findComplex(FindComplexRequest $req): FindComplexResponse
111
    {
112
        $json = $this->speedy->findComplex($req);
113
114
        /** @var FindComplexResponse $response */
115
        $response = $this->deserialize(json: $json, type: FindComplexResponse::class);
0 ignored issues
show
Bug introduced by
It seems like $json can also be of type object; however, parameter $json of VasilDakov\Speedy\Speedy...ecorator::deserialize() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

115
        $response = $this->deserialize(/** @scrutinizer ignore-type */ json: $json, type: FindComplexResponse::class);
Loading history...
116
117
        return $response;
118
    }
119
120
    public function findStreet(FindStreetRequest $req): FindStreetResponse
121
    {
122
        $json = $this->speedy->findStreet($req);
123
124
        /** @var FindStreetResponse $response */
125
        $response = $this->deserialize(json: $json, type: FindStreetResponse::class);
0 ignored issues
show
Bug introduced by
It seems like $json can also be of type object; however, parameter $json of VasilDakov\Speedy\Speedy...ecorator::deserialize() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

125
        $response = $this->deserialize(/** @scrutinizer ignore-type */ json: $json, type: FindStreetResponse::class);
Loading history...
126
127
        return $response;
128
    }
129
130
    public function createShipment(CreateShipmentRequest $req): CreateShipmentResponse
131
    {
132
        $json = $this->speedy->createShipment($req);
133
134
        /** @var CreateShipmentResponse $response */
135
        $response = $this->deserialize(json: $json, type: CreateShipmentResponse::class);
0 ignored issues
show
Bug introduced by
It seems like $json can also be of type object; however, parameter $json of VasilDakov\Speedy\Speedy...ecorator::deserialize() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

135
        $response = $this->deserialize(/** @scrutinizer ignore-type */ json: $json, type: CreateShipmentResponse::class);
Loading history...
136
137
        return $response;
138
    }
139
140
    public function track(TrackRequest $object): TrackResponse
141
    {
142
        $json = $this->speedy->track($object);
143
144
        /** @var TrackResponse $response */
145
        $response = $this->deserialize(json: $json, type: TrackResponse::class);
0 ignored issues
show
Bug introduced by
It seems like $json can also be of type object; however, parameter $json of VasilDakov\Speedy\Speedy...ecorator::deserialize() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

145
        $response = $this->deserialize(/** @scrutinizer ignore-type */ json: $json, type: TrackResponse::class);
Loading history...
146
147
        return $response;
148
    }
149
150
    public function calculate(CalculationRequest $object): CalculationResponse
151
    {
152
        $json = $this->speedy->calculate($object);
153
154
        /** @var CalculationResponse $response */
155
        $response = $this->deserialize(json: $json, type: CalculationResponse::class);
0 ignored issues
show
Bug introduced by
It seems like $json can also be of type object; however, parameter $json of VasilDakov\Speedy\Speedy...ecorator::deserialize() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

155
        $response = $this->deserialize(/** @scrutinizer ignore-type */ json: $json, type: CalculationResponse::class);
Loading history...
156
157
        return $response;
158
    }
159
160
    public function print(PrintRequest $object): PrintResponse
161
    {
162
        return new PrintResponse();
163
    }
164
165
    public function destination(DestinationServicesRequest $object): DestinationServicesResponse
166
    {
167
        $json = $this->speedy->destination($object);
168
169
        /** @var DestinationServicesResponse $response */
170
        $response = $this->deserialize(json: $json, type: DestinationServicesResponse::class);
0 ignored issues
show
Bug introduced by
It seems like $json can also be of type object; however, parameter $json of VasilDakov\Speedy\Speedy...ecorator::deserialize() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

170
        $response = $this->deserialize(/** @scrutinizer ignore-type */ json: $json, type: DestinationServicesResponse::class);
Loading history...
171
172
        return $response;
173
    }
174
}
175