Passed
Push — main ( a8b0f9...5ab65b )
by Vasil
03:25
created

Econt   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 149
Duplicated Lines 0 %

Test Coverage

Coverage 76.81%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 48
dl 0
loc 149
ccs 53
cts 69
cp 0.7681
rs 10
c 1
b 0
f 0
wmc 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getCountries() 0 11 1
A getClientProfiles() 0 11 1
A getCities() 0 11 1
A createLabel() 0 3 1
A deleteLabels() 0 3 1
A getShipmentStatuses() 0 11 1
A getOffices() 0 11 1
A createRequest() 0 15 1
A getStreets() 0 11 1
A createLabels() 0 3 1
A getQuarters() 0 3 1
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 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...
96
    {
97 2
        $request = $this->createRequest(
98 2
            RequestMethodInterface::METHOD_POST,
99 2
            self::API_URL . '/ee/services/Nomenclatures/NomenclaturesService.getStreets.json',
100 2
            $object->toArray()
101 2
        );
102
103 2
        $response = $this->client->sendRequest($request);
104
105 2
        return $response->getBody()->getContents();
106
    }
107
108
109
    public function getQuarters(array $data): string
110
    {
111
        return '';
112
    }
113
114
115
116
    public function getShipmentStatuses(array $data): string
117
    {
118
        $request = $this->createRequest(
119
            RequestMethodInterface::METHOD_POST,
120
            self::API_URL . '/ee/services/Shipments/ShipmentService.getShipmentStatuses.json',
121
            $data
122
        );
123
124
        $response = $this->client->sendRequest($request);
125
126
        return $response->getBody()->getContents();
127
    }
128
129
130
    /**
131
     * @param string $method
132
     * @param string $uri
133
     * @param array $data
134
     * @return RequestInterface
135
     */
136 12
    private function createRequest(string $method, string $uri, array $data): RequestInterface
137
    {
138 12
        $request = $this->factory->createRequest($method, $uri);
139
140 12
        $request = $request->withAddedHeader('Content-Type', 'application/json');
141 12
        $request = $request->withAddedHeader(
142 12
            'Authorization',
143 12
            'Basic ' . base64_encode(
144 12
                $this->configuration->username . ":" . $this->configuration->password
145 12
            )
146 12
        );
147
148 12
        $request->getBody()->write(json_encode($data));
149
150 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...
151
    }
152
153
154
155
    public function createLabel(array $data): string
156
    {
157
        return '';
158
    }
159
160
    public function createLabels(array $data): string
161
    {
162
        return '';
163
    }
164
165
    public function deleteLabels(array $data): string
166
    {
167
        return '';
168
    }
169
}
170