Client::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 24
ccs 15
cts 15
cp 1
rs 9.7998
cc 1
nc 1
nop 4
crap 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace DMT\Insolvency;
4
5
use DateTime;
6
use DMT\CommandBus\Validator\ValidationMiddleware;
7
use DMT\Http\Client\RequestHandler;
8
use DMT\Insolvency\Exception\Exception;
9
use DMT\Insolvency\Exception\ExceptionMiddleware;
10
use DMT\Insolvency\Http\GetReportHandler;
11
use DMT\Insolvency\Http\Middleware\ExceptionMiddleware as HttpExceptionMiddleware;
12
use DMT\Insolvency\Http\Middleware\SoapActionMiddleware;
13
use DMT\Insolvency\Http\Request\GetReport;
14
use DMT\Insolvency\Http\Response\GetReportResponse;
15
use DMT\Insolvency\Model\BeschikbareVerslagen;
16
use DMT\Insolvency\Model\Document;
17
use DMT\Insolvency\Model\Insolvente;
18
use DMT\Insolvency\Model\LastUpdate;
19
use DMT\Insolvency\Model\PublicatieLijst;
20
use DMT\Insolvency\Model\VerwijderdePublicatieLijst;
21
use DMT\Insolvency\Soap\Handler as SoapHandler;
22
use DMT\Insolvency\Soap\Request;
23
use DMT\Insolvency\Soap\Request as SoapRequest;
24
use DMT\Insolvency\Soap\Response;
25
use DMT\Insolvency\Soap\Serializer\SoapSerializer;
26
use GuzzleHttp\Client as HttpClient;
27
use JMS\Serializer\SerializerInterface;
28
use League\Tactician\CommandBus;
29
use League\Tactician\Handler\CommandHandlerMiddleware;
30
use League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor;
31
use League\Tactician\Handler\Locator\CallableLocator;
32
use League\Tactician\Handler\MethodNameInflector\HandleInflector;
33
use League\Tactician\Plugins\LockingMiddleware;
34
use Psr\Http\Client\ClientInterface;
35
use Psr\Http\Message\RequestFactoryInterface;
36
37
/**
38
 * Class Client
39
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
40
final class Client
41
{
42
    private Config $config;
0 ignored issues
show
Coding Style introduced by
Private member variable "config" must be prefixed with an underscore
Loading history...
43
    private ClientInterface $client;
0 ignored issues
show
Coding Style introduced by
Private member variable "client" must be prefixed with an underscore
Loading history...
44
    private RequestFactoryInterface $requestFactory;
0 ignored issues
show
Coding Style introduced by
Private member variable "requestFactory" must be prefixed with an underscore
Loading history...
45
    private SerializerInterface $serializer;
0 ignored issues
show
Coding Style introduced by
Private member variable "serializer" must be prefixed with an underscore
Loading history...
46
    private CommandBus $commandBus;
0 ignored issues
show
Coding Style introduced by
Private member variable "commandBus" must be prefixed with an underscore
Loading history...
47
48
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
49
     * @param Config $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 18 spaces after parameter type; 1 found
Loading history...
50
     * @param ClientInterface $client
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
51
     * @param RequestFactoryInterface $requestFactory
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
52
     * @param SoapSerializer|null $serializer
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
53
     */
54 11
    public function __construct(
55
        Config                  $config,
56
        ClientInterface         $client,
57
        RequestFactoryInterface $requestFactory,
58
        SoapSerializer          $serializer = null
59
    )
60
    {
0 ignored issues
show
Coding Style introduced by
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Loading history...
61 11
        $this->config = $config;
62 11
        $this->client = $client;
63 11
        $this->requestFactory = $requestFactory;
64 11
        $this->serializer = $serializer ?? new SoapSerializer($this, $config);
65
66 11
        $this->commandBus = new CommandBus([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
67 11
            new LockingMiddleware(),
68 11
            new ExceptionMiddleware(),
69 11
            new ValidationMiddleware(),
70 11
            new CommandHandlerMiddleware(
71 11
                new ClassNameExtractor(),
72 11
                new CallableLocator(
73
                    function (string $request) {
74 11
                        return $this->getHandler($request);
75 11
                    }
76
                ),
77 11
                new HandleInflector()
78
            )
79
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
80 11
    }
81
82
    /**
83
     * Search for publications of a specific insolvency.
84
     *
85
     * @param string $insolvencyID the insolvency identification.
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
86
     * @param string|null $court the count (number) where the insolvency is registered.
0 ignored issues
show
Coding Style introduced by
Expected 8 spaces after parameter name; 1 found
Loading history...
87
     *
88
     * @return PublicatieLijst
89
     * @throws Exception
90
     */
91 1
    public function searchInsolvencyId(string $insolvencyID, string $court = null): PublicatieLijst
92
    {
93 1
        $request = new Request\SearchInsolvencyID();
94 1
        $request->insolvencyID = $insolvencyID;
95 1
        $request->court = $court;
96
97
        /** @var Response\SearchInsolvencyIDResponse $response */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
98 1
        $response = $this->process($request);
99
100 1
        return $response->result->publicatieLijst;
101
    }
102
103
    /**
104
     * Search for publications for a person.
105
     *
106
     * @param DateTime|null $dateOfBirth the date of birth of the person.
107
     * @param string|null $prefix the surname prefix.
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter name; 1 found
Loading history...
108
     * @param string|null $surname the surname of the person.
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter name; 1 found
Loading history...
109
     * @param int|null $houseNumber the house number of the person's address.
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
110
     * @param string|null $postalCode the postcode of the person's address.
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 1 found
Loading history...
111
     *
112
     * @return PublicatieLijst
113
     * @throws Exception
114
     */
115 1
    public function searchNaturalPerson(
116
        DateTime $dateOfBirth = null,
117
        string   $prefix = null,
118
        string   $surname = null,
119
        int      $houseNumber = null,
120
        string   $postalCode = null
121
    ): PublicatieLijst
122
    {
0 ignored issues
show
Coding Style introduced by
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Loading history...
123 1
        $request = new Request\SearchNaturalPerson();
124 1
        $request->dateOfBirth = $dateOfBirth;
125 1
        $request->prefix = $prefix;
126 1
        $request->surname = $surname;
127 1
        $request->houseNumber = $houseNumber;
128 1
        $request->postalCode = $postalCode;
129
130
        /** @var Response\SearchNaturalPersonResponse $response */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
131 1
        $response = $this->process($request);
132
133 1
        return $response->result->publicatieLijst;
134
    }
135
136
    /**
137
     * Search for publications of an undertaking.
138
     *
139
     * @param string|null $name the name of the undertaking.
0 ignored issues
show
Coding Style introduced by
Expected 17 spaces after parameter name; 1 found
Loading history...
140
     * @param string|null $commercialRegisterID the chamber of commerce number.
141
     * @param string|null $postalCode the postcode of the undertaking's address.
0 ignored issues
show
Coding Style introduced by
Expected 11 spaces after parameter name; 1 found
Loading history...
142
     * @param int|null $houseNumber the house number of the undertaking' address.
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 10 spaces after parameter name; 1 found
Loading history...
143
     *
144
     * @return PublicatieLijst
145
     * @throws Exception
146
     */
147 1
    public function searchUndertaking(
148
        string $name = null,
149
        string $commercialRegisterID = null,
150
        string $postalCode = null,
151
        int    $houseNumber = null
152
    ): PublicatieLijst
153
    {
0 ignored issues
show
Coding Style introduced by
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Loading history...
154 1
        $request = new Request\SearchUndertaking();
155 1
        $request->name = $name;
156 1
        $request->commercialRegisterID = $commercialRegisterID;
157 1
        $request->postalCode = $postalCode;
158 1
        $request->houseNumber = $houseNumber;
159
160
        /** @var Response\SearchUndertakingResponse $response */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
161 1
        $response = $this->process($request);
162
163 1
        return $response->result->publicatieLijst;
164
    }
165
166
    /**
167
     * Get insolvency case.
168
     *
169
     * @param string $publicationNumber the publication number of the case.
170
     * @param bool $includeReports set to true to include reports.
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter name; 1 found
Loading history...
171
     *
172
     * @return Insolvente
173
     * @throws Exception
174
     */
175 7
    public function getCase(string $publicationNumber, bool $includeReports = false): Insolvente
176
    {
177 7
        $request = $includeReports ? new Request\GetCaseWithReports() : new Request\GetCase();
178 7
        $request->publicationNumber = $publicationNumber;
179
180
        /** @var Response\GetCaseResponse $response */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
181 7
        $response = $this->process($request);
182
183 7
        return $response->result->inspubWebserviceInsolvente->insolvente;
184
    }
185
186
    /**
187
     * Get a report for an insolvency.
188
     *
189
     * @param string $reportId the report identification number.
190
     *
191
     * @return Document
192
     * @throws Exception
193
     */
194 3
    public function getReport(string $reportId): Document
195
    {
196 3
        $request = new GetReport();
197 3
        $request->reportId = $reportId;
198
199
        /** @var GetReportResponse $response */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
200 3
        $response = $this->process($request);
201
202 3
        return $response->result->report;
203
204
    }
205
206
    /**
207
     * Get the date when the latest publication is added.
208
     *
209
     * @return LastUpdate
210
     * @throws Exception
211
     */
212 1
    public function getLastUpdate(): LastUpdate
213
    {
214
        /** @var Response\GetLastUpdateResponse $response */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
215 1
        $response = $this->process(new Request\GetLastUpdate());
216
217 1
        return $response->result->lastUpdate;
218
    }
219
220
    /**
221
     * Search for publications of a specific date.
222
     *
223
     * @param DateTime $date tne date of the publications to look up.
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter name; 1 found
Loading history...
224
     * @param string $court the court (number) where the publications are registered.
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 1 found
Loading history...
225
     * @param string|null $pubType the type of publication.
226
     *
227
     * @return PublicatieLijst
228
     * @throws Exception
229
     */
230 1
    public function searchByDate(DateTime $date, string $court, string $pubType = null): PublicatieLijst
231
    {
232 1
        $request = new Request\SearchByDate();
233 1
        $request->date = $date;
234 1
        $request->court = $court;
235 1
        $request->pubType = $pubType;
236
237
        /** @var Response\SearchByDateResponse $response */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
238 1
        $response = $this->process($request);
239
240 1
        return $response->result->publicatieLijst;
241
    }
242
243
    /**
244
     * Search for publications of the last mutated/added insolvencies for data replication.
245
     *
246
     * @param DateTime $modifyDate the modified date since.
247
     *
248
     * @return PublicatieLijst
249
     * @throws Exception
250
     */
251 1
    public function searchModifiedSince(DateTime $modifyDate): PublicatieLijst
252
    {
253 1
        $request = new Request\SearchModifiedSince();
254 1
        $request->modifyDate = $modifyDate;
255
256
        /** @var Response\SearchModifiedSinceResponse $response */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
257 1
        $response = $this->process($request);
258
259 1
        return $response->result->publicatieLijst;
260
    }
261
262
    /**
263
     * Search for removed publications for data replication.
264
     *
265
     * @param DateTime $modifyDate the modified date since.
266
     *
267
     * @return VerwijderdePublicatieLijst
268
     * @throws Exception
269
     */
270 1
    public function searchRemovedSince(DateTime $modifyDate): VerwijderdePublicatieLijst
271
    {
272 1
        $request = new Request\SearchRemovedSince();
273 1
        $request->modifyDate = $modifyDate;
274
275
        /** @var Response\SearchRemovedSinceResponse $response */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
276 1
        $response = $this->process($request);
277
278 1
        return $response->result->verwijderdePublicatieLijst;
279
    }
280
281
    /**
282
     * Search for added and modified reposts in a given time period.
283
     *
284
     * @param DateTime $datetimeFrom the start date.
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
285
     * @param DateTime|null $datetimeTo the end date.
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter name; 1 found
Loading history...
286
     *
287
     * @return BeschikbareVerslagen
288
     * @throws Exception
289
     */
290 1
    public function searchReportsSince(DateTime $datetimeFrom, DateTime $datetimeTo = null): BeschikbareVerslagen
291
    {
292 1
        $request = new Request\SearchReportsSince();
293 1
        $request->datetimeFrom = $datetimeFrom;
294 1
        $request->datetimeTo = $datetimeTo ?? new DateTime();
295
296
        /** @var Response\SearchReportsSinceResponse $response */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
297 1
        $response = $this->process($request);
298
299 1
        return $response->result->beschikbareVerslagen;
300
    }
301
302
    /**
303
     * Process a request.
304
     *
305
     * @param Request|GetReport $request
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
306
     *
307
     * @return Response|GetReportResponse
308
     * @throws Exception
309
     */
310 11
    private function process($request)
0 ignored issues
show
Coding Style introduced by
Private method name "Client::process" must be prefixed with an underscore
Loading history...
311
    {
312 11
        return $this->commandBus->handle($request);
313
    }
314
315
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
316
     * @param string $request
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 4 spaces but found 1
Loading history...
317
     * @return SoapHandler|object
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
Coding Style introduced by
Tag value for @return tag indented incorrectly; expected 3 spaces but found 1
Loading history...
318
     * @internal
0 ignored issues
show
Coding Style introduced by
Tag @internal cannot be grouped with parameter tags in a doc comment
Loading history...
319
     */
320 11
    private function getHandler(string $request)
0 ignored issues
show
Coding Style introduced by
Private method name "Client::getHandler" must be prefixed with an underscore
Loading history...
321
    {
322 11
        $exceptionMiddleware = new HttpExceptionMiddleware();
323 11
        if (!is_a($request, SoapRequest::class, true)) {
324 3
            return new GetReportHandler(
325 3
                $this->config,
326 3
                new RequestHandler($this->client, $exceptionMiddleware),
327 3
                $this->requestFactory
328
            );
329
        }
330
331 10
        $soapActionMiddleware =new SoapActionMiddleware();
332 10
        return new SoapHandler(
333 10
            $this->config,
334 10
            new RequestHandler($this->client, $exceptionMiddleware, $soapActionMiddleware),
335 10
            $this->requestFactory,
336 10
            $this->serializer
337
        );
338
    }
339
}
340