Completed
Pull Request — master (#8)
by Tomáš
03:09
created

Balikobot::getBranchesForLocation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
ccs 6
cts 6
cp 1
cc 2
nc 2
nop 8
crap 2

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Inspirum\Balikobot\Services;
4
5
use Inspirum\Balikobot\Contracts\RequesterInterface;
6
use Inspirum\Balikobot\Definitions\Option;
7
use Inspirum\Balikobot\Definitions\Shipper;
8
use Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection;
9
use Inspirum\Balikobot\Model\Aggregates\PackageCollection;
10
use Inspirum\Balikobot\Model\Aggregates\PackageTransportCostCollection;
11
use Inspirum\Balikobot\Model\Values\Branch;
12
use Inspirum\Balikobot\Model\Values\Country;
13
use Inspirum\Balikobot\Model\Values\OrderedPackage;
14
use Inspirum\Balikobot\Model\Values\OrderedShipment;
15
use Inspirum\Balikobot\Model\Values\Package;
16
use Inspirum\Balikobot\Model\Values\PackageStatus;
17
use Inspirum\Balikobot\Model\Values\PackageTransportCost;
18
use Inspirum\Balikobot\Model\Values\PostCode;
19
20
class Balikobot
21
{
22
    /**
23
     * Balikobot API
24
     *
25
     * @var \Inspirum\Balikobot\Services\Client
26
     */
27
    private $client;
28
29
    /**
30
     * Balikobot constructor
31
     *
32
     * @param \Inspirum\Balikobot\Contracts\RequesterInterface $requester
33
     */
34 115
    public function __construct(RequesterInterface $requester)
35
    {
36 115
        $this->client = new Client($requester);
37 115
    }
38
39
    /**
40
     * All supported shipper services
41
     *
42
     * @return array<string>
43
     */
44 1
    public function getShippers(): array
45
    {
46 1
        return Shipper::all();
47
    }
48
49
    /**
50
     * Add packages
51
     *
52
     * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages
53
     *
54
     * @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[]
55
     *
56
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
57
     */
58 11
    public function addPackages(PackageCollection $packages): OrderedPackageCollection
59
    {
60 11
        $labelsUrl = null;
61 11
        $response  = $this->client->addPackages($packages->getShipper(), $packages->toArray(), $labelsUrl);
62
63 10
        $orderedPackages = new OrderedPackageCollection();
64 10
        $orderedPackages->setLabelsUrl($labelsUrl);
65
66 10
        foreach ($response as $i => $package) {
67 10
            $orderedPackages->add(OrderedPackage::newInstanceFromData($packages->getShipper(), $package));
68
        }
69
70 10
        return $orderedPackages;
71
    }
72
73
    /**
74
     * Exports order into Balikobot system
75
     *
76
     * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages
77
     *
78
     * @return void
79
     *
80
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
81
     */
82 3
    public function dropPackages(OrderedPackageCollection $packages): void
83
    {
84 3
        $this->client->dropPackages($packages->getShipper(), $packages->getPackageIds());
85 2
    }
86
87
    /**
88
     * Exports order into Balikobot system
89
     *
90
     * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package
91
     *
92
     * @return void
93
     *
94
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
95
     */
96 1
    public function dropPackage(OrderedPackage $package): void
97
    {
98 1
        $this->client->dropPackage($package->getShipper(), $package->getPackageId());
99 1
    }
100
101
    /**
102
     * Order shipment
103
     *
104
     * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages
105
     *
106
     * @return \Inspirum\Balikobot\Model\Values\OrderedShipment
107
     *
108
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
109
     */
110 5
    public function orderShipment(OrderedPackageCollection $packages): OrderedShipment
111
    {
112 5
        $response = $this->client->orderShipment($packages->getShipper(), $packages->getPackageIds());
113
114 4
        return OrderedShipment::newInstanceFromData($packages->getShipper(), $packages->getPackageIds(), $response);
115
    }
116
117
    /**
118
     * Track package
119
     *
120
     * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package
121
     *
122
     * @return array<\Inspirum\Balikobot\Model\Values\PackageStatus>|\Inspirum\Balikobot\Model\Values\PackageStatus[]
123
     *
124
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
125
     */
126 3
    public function trackPackage(OrderedPackage $package): array
127
    {
128 3
        $packages = new OrderedPackageCollection();
129 3
        $packages->add($package);
130
131 3
        return $this->trackPackages($packages)[0];
132
    }
133
134
    /**
135
     * Track packages
136
     *
137
     * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages
138
     *
139
     * @return array<array<\Inspirum\Balikobot\Model\Values\PackageStatus>>|\Inspirum\Balikobot\Model\Values\PackageStatus[][]
140
     *
141
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
142
     */
143 6
    public function trackPackages(OrderedPackageCollection $packages): array
144
    {
145 6
        $response = $this->client->trackPackages($packages->getShipper(), $packages->getCarrierIds());
146
147 5
        $statuses = [];
148
149 5
        foreach ($response as $responseStatuses) {
150 5
            $statuses[] = $this->createPackageStatusesCollection($responseStatuses);
151
        }
152
153 5
        return $statuses;
154
    }
155
156
    /**
157
     * Track package last status
158
     *
159
     * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package
160
     *
161
     * @return \Inspirum\Balikobot\Model\Values\PackageStatus
162
     *
163
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
164
     */
165 2
    public function trackPackageLastStatus(OrderedPackage $package): PackageStatus
166
    {
167 2
        $packages = new OrderedPackageCollection();
168 2
        $packages->add($package);
169
170 2
        return $this->trackPackagesLastStatus($packages)[0];
171
    }
172
173
    /**
174
     * Track package last status
175
     *
176
     * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages
177
     *
178
     * @return array<\Inspirum\Balikobot\Model\Values\PackageStatus>|\Inspirum\Balikobot\Model\Values\PackageStatus[]
179
     *
180
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
181
     */
182 5
    public function trackPackagesLastStatus(OrderedPackageCollection $packages): array
183
    {
184 5
        $response = $this->client->trackPackagesLastStatus($packages->getShipper(), $packages->getCarrierIds());
185
186 5
        return $this->createPackageStatusesCollection($response);
187
    }
188
189
    /**
190
     * Create package statuses collection for package
191
     *
192
     * @param array<array<string,float|string|null>> $response
193
     *
194
     * @return array<\Inspirum\Balikobot\Model\Values\PackageStatus>
195
     */
196 10
    private function createPackageStatusesCollection(array $response): array
197
    {
198 10
        $statuses = [];
199
200 10
        foreach ($response as $status) {
201 10
            $statuses[] = PackageStatus::newInstanceFromData($status);
202
        }
203
204 10
        return $statuses;
205
    }
206
207
    /**
208
     * Get overview for given shipper
209
     *
210
     * @param string $shipper
211
     *
212
     * @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[]
213
     *
214
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
215
     */
216 3
    public function getOverview(string $shipper): OrderedPackageCollection
217
    {
218 3
        $response = $this->client->getOverview($shipper);
219
220 3
        $response = $response['packages'];
221
222 3
        $orderedPackages = new OrderedPackageCollection();
223
224 3
        foreach ($response as $package) {
225 2
            $orderedPackage = OrderedPackage::newInstanceFromData($shipper, $package);
226 2
            $orderedPackages->add($orderedPackage);
227
        }
228
229 3
        return $orderedPackages;
230
    }
231
232
    /**
233
     * Get labels for orders
234
     *
235
     * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages
236
     *
237
     * @return string
238
     *
239
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
240
     */
241 4
    public function getLabels(OrderedPackageCollection $packages): string
242
    {
243 4
        return $this->client->getLabels($packages->getShipper(), $packages->getPackageIds());
244
    }
245
246
    /**
247
     * Gets complete information about a package
248
     *
249
     * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package
250
     *
251
     * @return \Inspirum\Balikobot\Model\Values\Package
252
     *
253
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
254
     */
255 4
    public function getPackageInfo(OrderedPackage $package): Package
256
    {
257 4
        $response = $this->client->getPackageInfoByCarrierId($package->getShipper(), $package->getCarrierId());
258
259
        unset(
260 3
            $response['package_id'],
261 3
            $response['eshop_id'],
262 3
            $response['carrier_id'],
263 3
            $response['track_url'],
264 3
            $response['label_url'],
265 3
            $response['carrier_id_swap'],
266 3
            $response['pieces']
267
        );
268
269 3
        $options              = $response;
270 3
        $options[Option::EID] = $package->getBatchId();
271
272 3
        return new Package($options);
273
    }
274
275
    /**
276
     * Gets complete information about a package
277
     *
278
     * @param string $shipper
279
     * @param string $orderId
280
     *
281
     * @return \Inspirum\Balikobot\Model\Values\OrderedShipment
282
     *
283
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
284
     */
285 4
    public function getOrder(string $shipper, string $orderId): OrderedShipment
286
    {
287 4
        $response = $this->client->getOrder($shipper, $orderId);
288
289 3
        return OrderedShipment::newInstanceFromData($shipper, $response['package_ids'], $response);
290
    }
291
292
    /**
293
     * Returns available services for the given shipper
294
     *
295
     * @param string $shipper
296
     *
297
     * @return array<string,string>
298
     *
299
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
300
     */
301 6
    public function getServices(string $shipper): array
302
    {
303 6
        return $this->client->getServices($shipper);
304
    }
305
306
    /**
307
     * Returns available B2A services for the given shipper
308
     *
309
     * @param string $shipper
310
     *
311
     * @return array<string,string>
312
     *
313
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
314
     */
315 3
    public function getB2AServices(string $shipper): array
316
    {
317 3
        return $this->client->getB2AServices($shipper);
318
    }
319
320
    /**
321
     * Returns all manipulation units for the given shipper
322
     *
323
     * @param string $shipper
324
     * @param bool   $fullData
325
     *
326
     * @return array<string|array>
327
     *
328
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
329
     */
330 5
    public function getManipulationUnits(string $shipper, bool $fullData = false): array
331
    {
332 5
        return $this->client->getManipulationUnits($shipper, $fullData);
333
    }
334
335
    /**
336
     * Returns available manipulation units for the given shipper
337
     *
338
     * @param string $shipper
339
     * @param bool   $fullData
340
     *
341
     * @return array<string|array>
342
     *
343
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
344
     */
345 5
    public function getActivatedManipulationUnits(string $shipper, bool $fullData = false): array
346
    {
347 5
        return $this->client->getActivatedManipulationUnits($shipper, $fullData);
348
    }
349
350
    /**
351
     * Get all available branches
352
     *
353
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
354
     *
355
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
356
     */
357 1
    public function getBranches(): iterable
358
    {
359 1
        foreach ($this->getShippers() as $shipper) {
360 1
            yield from $this->getBranchesForShipper($shipper);
361
        }
362 1
    }
363
364
    /**
365
     * Get all available branches for countries
366
     *
367
     * @param array<string> $countries
368
     *
369
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
370
     *
371
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
372
     */
373 1
    public function getBranchesForCountries(array $countries): iterable
374
    {
375 1
        foreach ($this->getShippers() as $shipper) {
376 1
            yield from $this->getBranchesForShipperForCountries($shipper, $countries);
377
        }
378 1
    }
379
380
    /**
381
     * Get all available branches for given shipper
382
     *
383
     * @param string $shipper
384
     *
385
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
386
     *
387
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
388
     */
389 2
    public function getBranchesForShipper(string $shipper): iterable
390
    {
391 2
        foreach ($this->getServicesForShipper($shipper) as $service) {
392 2
            yield from $this->getBranchesForShipperService($shipper, $service);
393
        }
394 2
    }
395
396
    /**
397
     * Get all available branches for given shipper for countries
398
     *
399
     * @param string        $shipper
400
     * @param array<string> $countries
401
     *
402
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
403
     *
404
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
405
     */
406 2
    public function getBranchesForShipperForCountries(string $shipper, array $countries): iterable
407
    {
408 2
        foreach ($this->getServicesForShipper($shipper) as $service) {
409 2
            yield from $this->getBranchesForShipperServiceForCountries($shipper, $service, $countries);
410
        }
411 2
    }
412
413
    /**
414
     * Get services for shipper
415
     *
416
     * @param string $shipper
417
     *
418
     * @return array<string|null>
419
     *
420
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
421
     */
422 4
    private function getServicesForShipper(string $shipper): array
423
    {
424 4
        return array_keys($this->getServices($shipper)) ?: [null];
425
    }
426
427
    /**
428
     * Get all available branches for given shipper and service type for countries
429
     *
430
     * @param string        $shipper
431
     * @param string|null   $service
432
     * @param array<string> $countries
433
     *
434
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
435
     *
436
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
437
     */
438 3
    public function getBranchesForShipperServiceForCountries(
439
        string $shipper,
440
        ?string $service,
441
        array $countries
442
    ): iterable {
443 3
        foreach ($this->getAllBranchesForShipperServiceForCountries($shipper, $service, $countries) as $branch) {
444 3
            if (in_array($branch->getCountry(), $countries)) {
445 3
                yield $branch;
446
            }
447
        }
448 3
    }
449
450
    /**
451
     * Get all available branches for given shipper and service type filtered by countries if possible
452
     *
453
     * @param string        $shipper
454
     * @param string|null   $service
455
     * @param array<string> $countries
456
     *
457
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
458
     *
459
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
460
     */
461 3
    private function getAllBranchesForShipperServiceForCountries(
462
        string $shipper,
463
        ?string $service,
464
        array $countries
465
    ): iterable {
466 3
        if (Shipper::hasBranchCountryFilterSupport($shipper) === false) {
467 2
            return yield from $this->getBranchesForShipperService($shipper, $service);
468
        }
469
470 2
        foreach ($countries as $country) {
471 2
            yield from $this->getBranchesForShipperService($shipper, $service, $country);
472
        }
473 2
    }
474
475
    /**
476
     * Get all available branches for given shipper and service type
477
     *
478
     * @param string      $shipper
479
     * @param string|null $service
480
     * @param string|null $country
481
     *
482
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
483
     *
484
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
485
     */
486 7
    public function getBranchesForShipperService(string $shipper, ?string $service, string $country = null): iterable
487
    {
488 7
        $useFullBranchRequest = Shipper::hasFullBranchesSupport($shipper, $service);
489
490 7
        foreach ($this->client->getBranches($shipper, $service, $useFullBranchRequest, $country) as $branch) {
491 3
            yield Branch::newInstanceFromData($shipper, $service, $branch);
492
        }
493 6
    }
494
495
    /**
496
     * Get all available branches for given shipper
497
     *
498
     * @param string      $shipper
499
     * @param string      $country
500
     * @param string      $city
501
     * @param string|null $postcode
502
     * @param string|null $street
503
     * @param int|null    $maxResults
504
     * @param float|null  $radius
505
     * @param string|null $type
506
     *
507
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
508
     *
509
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
510
     */
511 5
    public function getBranchesForLocation(
512
        string $shipper,
513
        string $country,
514
        string $city,
515
        string $postcode = null,
516
        string $street = null,
517
        int $maxResults = null,
518
        float $radius = null,
519
        string $type = null
520
    ): iterable {
521 5
        $branches = $this->client->getBranchesForLocation(
522 5
            $shipper,
523
            $country,
524
            $city,
525
            $postcode,
526
            $street,
527
            $maxResults,
528
            $radius,
529
            $type
530
        );
531
532 4
        foreach ($branches as $branch) {
533 2
            yield Branch::newInstanceFromData($shipper, null, $branch);
534
        }
535 3
    }
536
537
    /**
538
     * Returns list of countries where service with cash-on-delivery payment type is available in
539
     *
540
     * @param string $shipper
541
     *
542
     * @return array<array<int|string,array<string,array>>>
543
     *
544
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
545
     */
546 3
    public function getCodCountries(string $shipper): array
547
    {
548 3
        return $this->client->getCodCountries($shipper);
549
    }
550
551
    /**
552
     * Returns list of countries where service is available in
553
     *
554
     * @param string $shipper
555
     *
556
     * @return array<array<int|string,string>>
557
     *
558
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
559
     */
560 3
    public function getCountries(string $shipper): array
561
    {
562 3
        return $this->client->getCountries($shipper);
563
    }
564
565
    /**
566
     * Returns available branches for the given shipper and its service
567
     *
568
     * @param string      $shipper
569
     * @param string      $service
570
     * @param string|null $country
571
     *
572
     * @return \Generator|\Inspirum\Balikobot\Model\Values\PostCode[]
573
     *
574
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
575
     */
576 3
    public function getPostCodes(string $shipper, string $service, string $country = null): iterable
577
    {
578 3
        foreach ($this->client->getPostCodes($shipper, $service, $country) as $postcode) {
579 2
            yield PostCode::newInstanceFromData($shipper, $service, $postcode);
580
        }
581 2
    }
582
583
    /**
584
     * Check package(s) data
585
     *
586
     * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages
587
     *
588
     * @return void
589
     *
590
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
591
     */
592 3
    public function checkPackages(PackageCollection $packages): void
593
    {
594 3
        $this->client->checkPackages($packages->getShipper(), $packages->toArray());
595 2
    }
596
597
    /**
598
     * Returns available manipulation units for the given shipper
599
     *
600
     * @param string $shipper
601
     * @param bool   $fullData
602
     *
603
     * @return array<string|array>
604
     *
605
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
606
     */
607 5
    public function getAdrUnits(string $shipper, bool $fullData = false): array
608
    {
609 5
        return $this->client->getAdrUnits($shipper, $fullData);
610
    }
611
612
    /**
613
     * Returns available activated services for the given shipper
614
     *
615
     * @param string $shipper
616
     *
617
     * @return array<string,mixed>
618
     *
619
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
620
     */
621 3
    public function getActivatedServices(string $shipper): array
622
    {
623 3
        return $this->client->getActivatedServices($shipper);
624
    }
625
626
    /**
627
     * Order shipments from place B (typically supplier / previous consignee) to place A (shipping point)
628
     *
629
     * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages
630
     *
631
     * @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[]
632
     *
633
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
634
     */
635 5
    public function orderB2AShipment(PackageCollection $packages): OrderedPackageCollection
636
    {
637 5
        $response = $this->client->orderB2AShipment($packages->getShipper(), $packages->toArray());
638
639 4
        $orderedPackages = new OrderedPackageCollection();
640
641 4
        foreach ($response as $i => $package) {
642 4
            $package[Option::EID] = (string) $packages->offsetGet($i)->getEID();
643 4
            $orderedPackage       = OrderedPackage::newInstanceFromData($packages->getShipper(), $package);
644 4
            $orderedPackages->add($orderedPackage);
645
        }
646
647 4
        return $orderedPackages;
648
    }
649
650
    /**
651
     * Get PDF link with signed consignment delivery document by the recipient
652
     *
653
     * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package
654
     *
655
     * @return string
656
     *
657
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
658
     */
659 2
    public function getProofOfDelivery(OrderedPackage $package): string
660
    {
661 2
        $packages = new OrderedPackageCollection();
662 2
        $packages->add($package);
663
664 2
        return $this->getProofOfDeliveries($packages)[0];
665
    }
666
667
    /**
668
     * Get array of PDF links with signed consignment delivery document by the recipient
669
     *
670
     * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages
671
     *
672
     * @return array<string>
673
     *
674
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
675
     */
676 6
    public function getProofOfDeliveries(OrderedPackageCollection $packages): array
677
    {
678 6
        return $this->client->getProofOfDeliveries($packages->getShipper(), $packages->getCarrierIds());
679
    }
680
681
    /**
682
     * Obtain the price of carriage at consignment level
683
     *
684
     * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages
685
     *
686
     * @return \Inspirum\Balikobot\Model\Aggregates\PackageTransportCostCollection|\Inspirum\Balikobot\Model\Values\PackageTransportCost[]
687
     *
688
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
689
     */
690 4
    public function getTransportCosts(PackageCollection $packages): PackageTransportCostCollection
691
    {
692 4
        $response = $this->client->getTransportCosts($packages->getShipper(), $packages->toArray());
693
694 3
        $transportCosts = new PackageTransportCostCollection($packages->getShipper());
695
696 3
        foreach ($response as $i => $package) {
697 3
            $transportCost = PackageTransportCost::newInstanceFromData($packages->getShipper(), $package);
698 3
            $transportCosts->add($transportCost);
699
        }
700
701 3
        return $transportCosts;
702
    }
703
704
    /**
705
     * Get information on individual countries of the world
706
     *
707
     * @return array<string,\Inspirum\Balikobot\Model\Values\Country>|\Inspirum\Balikobot\Model\Values\Country[]
708
     *
709
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
710
     */
711 3
    public function getCountriesData(): array
712
    {
713 3
        $response = $this->client->getCountriesData();
714
715 3
        $countries = [];
716
717 3
        foreach ($response as $code => $country) {
718 2
            $countries[$code] = Country::newInstanceFromData($country);
719
        }
720
721 3
        return $countries;
722
    }
723
724
    /**
725
     * Method for obtaining news in the Balikobot API
726
     *
727
     * @return array<string,mixed>
728
     *
729
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
730
     */
731
    public function getChangelog(): array
732
    {
733
        return $this->client->getChangelog();
734
    }
735
}
736