Passed
Push — main ( 2bc5a4...5ffc2f )
by Vasil
16:31 queued 13:09
created

SpeedyModelDecorator::calculate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
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\Client\GetContractClientsRequest;
11
use VasilDakov\Speedy\Service\Client\GetContractClientsResponse;
12
use VasilDakov\Speedy\Service\Location\Complex\FindComplexRequest;
13
use VasilDakov\Speedy\Service\Location\Country\FindCountryRequest;
14
use VasilDakov\Speedy\Service\Location\Country\FindCountryResponse;
15
use VasilDakov\Speedy\Service\Location\Office\FindOfficeRequest;
16
use VasilDakov\Speedy\Service\Location\Site\FindSiteRequest;
17
use VasilDakov\Speedy\Service\Location\State\FindStateRequest;
18
use VasilDakov\Speedy\Service\Location\State\FindStateResponse;
19
use VasilDakov\Speedy\Service\Location\Street\FindStreetRequest;
20
use VasilDakov\Speedy\Service\Printing\PrintRequest;
21
use VasilDakov\Speedy\Service\Printing\PrintResponse;
22
use VasilDakov\Speedy\Service\Service\DestinationServicesRequest;
23
use VasilDakov\Speedy\Service\Shipment\CreateShipmentRequest;
24
use VasilDakov\Speedy\Service\Track\TrackRequest;
25
26
final class SpeedyModelDecorator implements SpeedyInterface
27
{
28
    private SpeedyInterface $speedy;
29
30
    private SerializerInterface $serializer;
31
32 4
    public function __construct(SpeedyInterface $speedy, SerializerInterface $serializer = null)
33
    {
34 4
        $this->speedy = $speedy;
35
36 4
        if (null === $serializer) {
37 1
            $serializer = (new SerializerFactory())();
38
        }
39 4
        $this->serializer = $serializer;
40
    }
41
42 1
    public function getContractClient(GetContractClientsRequest $req): GetContractClientsResponse
43
    {
44 1
        $json = $this->speedy->getContractClient($req);
45
46
        /** @var GetContractClientsResponse $response */
47 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

47
        $response = $this->deserialize(/** @scrutinizer ignore-type */ $json, GetContractClientsResponse::class);
Loading history...
48
49 1
        return $response;
50
    }
51
52 1
    public function findCountry(FindCountryRequest $req): FindCountryResponse
53
    {
54 1
        $json = $this->speedy->findCountry($req);
55
56
        /** @var GetContractClientsResponse $response */
57 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

57
        $response = $this->deserialize(/** @scrutinizer ignore-type */ json: $json, type: FindCountryResponse::class);
Loading history...
58
59 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...
60
    }
61
62
63 1
    public function findState(FindStateRequest $req): FindStateResponse
64
    {
65 1
        $json = $this->speedy->findState($req);
66
67
        /** @var FindStateResponse $response */
68 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

68
        $response = $this->deserialize(/** @scrutinizer ignore-type */ json: $json, type: FindStateResponse::class);
Loading history...
69
70 1
        return $response;
71
    }
72
73 3
    private function deserialize(string $json, string $type): object
74
    {
75 3
        return $this->serializer->deserialize(
76 3
            data: $json,
77 3
            type: $type,
78 3
            format: 'json'
79 3
        );
80
    }
81
82
    public function findSite(FindSiteRequest $req): string|object
83
    {
84
        // TODO: Implement findSite() method.
85
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return object|string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
86
87
    public function findOffice(FindOfficeRequest $req): string|object
88
    {
89
        // TODO: Implement findOffice() method.
90
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return object|string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
91
92
    public function findComplex(FindComplexRequest $req): string|object
93
    {
94
        // TODO: Implement findComplex() method.
95
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return object|string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
96
97
    public function findStreet(FindStreetRequest $req): string|object
98
    {
99
        // TODO: Implement findStreet() method.
100
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return object|string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
101
102
    public function createShipment(CreateShipmentRequest $req): string|object
103
    {
104
        // TODO: Implement createShipment() method.
105
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return object|string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
106
107
    public function track(TrackRequest $object): string|object
108
    {
109
        // TODO: Implement track() method.
110
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return object|string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
111
112
    public function calculate(CalculationRequest $object): string|object
113
    {
114
        // TODO: Implement calculate() method.
115
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return object|string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
116
117
    public function print(PrintRequest $object): PrintResponse
118
    {
119
        return new PrintResponse();
120
    }
121
122
    public function destination(DestinationServicesRequest $object): string|object
123
    {
124
        // TODO: Implement destination() method.
125
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return object|string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
126
}
127