Econt::getStreets()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 11
ccs 8
cts 8
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VasilDakov\Econt;
6
7
use Fig\Http\Message\RequestMethodInterface;
8
use Psr\Http\Client\ClientExceptionInterface;
9
use Psr\Http\Client\ClientInterface;
10
use Psr\Http\Message\RequestFactoryInterface;
11
use Psr\Http\Message\RequestInterface;
12
use VasilDakov\Econt\Request;
13
14
/**
15
 * Class Econt
16
 *
17
 * @author Vasil Dakov <[email protected]>
18
 */
19
final class Econt implements EcontInterface
20
{
21
    public const API_URL = 'https://demo.econt.com';
22
23 14
    public function __construct(
24
        private readonly Configuration $configuration,
0 ignored issues
show
Bug introduced by
The type VasilDakov\Econt\Configuration 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...
25
        private readonly ClientInterface $client,
26
        private readonly RequestFactoryInterface $factory
27
    ) {
28 14
    }
29
30
    /**
31
     * @throws ClientExceptionInterface
32
     */
33 2
    public function getClientProfiles(): string
34
    {
35 2
        $request = $this->createRequest(
36 2
            RequestMethodInterface::METHOD_POST,
37 2
            self::API_URL . '/ee/services/Profile/ProfileService.getClientProfiles.json',
38 2
            []
39 2
        );
40
41 2
        $response = $this->client->sendRequest($request);
42
43 2
        return $response->getBody()->getContents();
44
    }
45
46
    /**
47
     * @throws ClientExceptionInterface
48
     */
49 4
    public function getCountries(): string
50
    {
51 4
        $request = $this->createRequest(
52 4
            RequestMethodInterface::METHOD_POST,
53 4
            self::API_URL . '/ee/services/Nomenclatures/NomenclaturesService.getCountries.json',
54 4
            []
55 4
        );
56
57 4
        $response = $this->client->sendRequest($request);
58
59 4
        return $response->getBody()->getContents();
60
    }
61
62
    /**
63
     * @throws ClientExceptionInterface
64
     */
65 2
    public function getCities(Request\GetCitiesRequest $object): string
0 ignored issues
show
Bug introduced by
The type VasilDakov\Econt\Request\GetCitiesRequest 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...
66
    {
67 2
        $request = $this->createRequest(
68 2
            RequestMethodInterface::METHOD_POST,
69 2
            self::API_URL . '/ee/services/Nomenclatures/NomenclaturesService.getCities.json',
70 2
            $object->toArray()
71 2
        );
72
73 2
        $response = $this->client->sendRequest($request);
74
75 2
        return $response->getBody()->getContents();
76
    }
77
78
    /**
79
     * @throws ClientExceptionInterface
80
     */
81 2
    public function getOffices(Request\GetOfficesRequest $object): string
0 ignored issues
show
Bug introduced by
The type VasilDakov\Econt\Request\GetOfficesRequest 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...
82
    {
83 2
        $request = $this->createRequest(
84 2
            RequestMethodInterface::METHOD_POST,
85 2
            self::API_URL . '/ee/services/Nomenclatures/NomenclaturesService.getOffices.json',
86 2
            $object->toArray()
87 2
        );
88
89 2
        $response = $this->client->sendRequest($request);
90
91 2
        return $response->getBody()->getContents();
92
    }
93
94
95
    /**
96
     * @throws ClientExceptionInterface
97
     */
98 2
    public function getStreets(Request\GetStreetsRequest $object): string
0 ignored issues
show
Bug introduced by
The type VasilDakov\Econt\Request\GetStreetsRequest 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...
99
    {
100 2
        $request = $this->createRequest(
101 2
            RequestMethodInterface::METHOD_POST,
102 2
            self::API_URL . '/ee/services/Nomenclatures/NomenclaturesService.getStreets.json',
103 2
            $object->toArray()
104 2
        );
105
106 2
        $response = $this->client->sendRequest($request);
107
108 2
        return $response->getBody()->getContents();
109
    }
110
111
112
    public function getQuarters(Request\GetQuartersRequest $object): string
113
    {
114
        $request = $this->createRequest(
115
            RequestMethodInterface::METHOD_POST,
116
            self::API_URL . '/ee/services/Nomenclatures/NomenclaturesService.GetQuarters.json',
117
            $object->toArray()
118
        );
119
120
        $response = $this->client->sendRequest($request);
121
122
        return $response->getBody()->getContents();
123
    }
124
125
126
    /**
127
     * @throws ClientExceptionInterface
128
     */
129
    public function getShipmentStatuses(array $data): string
130
    {
131
        $request = $this->createRequest(
132
            RequestMethodInterface::METHOD_POST,
133
            self::API_URL . '/ee/services/Shipments/ShipmentService.getShipmentStatuses.json',
134
            $data
135
        );
136
137
        $response = $this->client->sendRequest($request);
138
139
        return $response->getBody()->getContents();
140
    }
141
142
143
    /**
144
     * @param string $method
145
     * @param string $uri
146
     * @param array $data
147
     * @return RequestInterface
148
     */
149 12
    private function createRequest(string $method, string $uri, array $data): RequestInterface
150
    {
151 12
        $request = $this->factory->createRequest($method, $uri);
152
153 12
        $request = $request->withAddedHeader('Content-Type', 'application/json');
154 12
        $request = $request->withAddedHeader(
155 12
            'Authorization',
156 12
            'Basic ' . base64_encode(
157 12
                $this->configuration->username . ":" . $this->configuration->password
158 12
            )
159 12
        );
160
161 12
        $request->getBody()->write(json_encode($data));
162
163 12
        return $request;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $request returns the type Psr\Http\Message\MessageInterface which includes types incompatible with the type-hinted return Psr\Http\Message\RequestInterface.
Loading history...
164
    }
165
166
167
168
    public function createLabel(array $data): string
169
    {
170
        return '';
171
    }
172
173
    public function createLabels(array $data): string
174
    {
175
        return '';
176
    }
177
178
    public function deleteLabels(array $data): string
179
    {
180
        return '';
181
    }
182
}
183