Completed
Pull Request — master (#8)
by Tomáš
02:25
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(
115 4
            $packages->getShipper(),
116 4
            $packages->getPackageIds(),
117
            $response
118
        );
119
    }
120
121
    /**
122
     * Track package
123
     *
124
     * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package
125
     *
126
     * @return array<\Inspirum\Balikobot\Model\Values\PackageStatus>|\Inspirum\Balikobot\Model\Values\PackageStatus[]
127
     *
128
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
129
     */
130 3
    public function trackPackage(OrderedPackage $package): array
131
    {
132 3
        $packages = new OrderedPackageCollection();
133 3
        $packages->add($package);
134
135 3
        return $this->trackPackages($packages)[0];
136
    }
137
138
    /**
139
     * Track packages
140
     *
141
     * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages
142
     *
143
     * @return array<array<\Inspirum\Balikobot\Model\Values\PackageStatus>>|\Inspirum\Balikobot\Model\Values\PackageStatus[][]
144
     *
145
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
146
     */
147 6
    public function trackPackages(OrderedPackageCollection $packages): array
148
    {
149 6
        $response = $this->client->trackPackages($packages->getShipper(), $packages->getCarrierIds());
150
151 5
        $statuses = [];
152
153 5
        foreach ($response as $i => $responseStatuses) {
154 5
            $statuses[$i] = [];
155
156 5
            foreach ($responseStatuses as $status) {
157 5
                $statuses[$i][] = PackageStatus::newInstanceFromData($status);
158
            }
159
        }
160
161 5
        return $statuses;
162
    }
163
164
    /**
165
     * Track package last status
166
     *
167
     * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package
168
     *
169
     * @return \Inspirum\Balikobot\Model\Values\PackageStatus
170
     *
171
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
172
     */
173 2
    public function trackPackageLastStatus(OrderedPackage $package): PackageStatus
174
    {
175 2
        $packages = new OrderedPackageCollection();
176 2
        $packages->add($package);
177
178 2
        return $this->trackPackagesLastStatus($packages)[0];
179
    }
180
181
    /**
182
     * Track package last status
183
     *
184
     * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages
185
     *
186
     * @return array<\Inspirum\Balikobot\Model\Values\PackageStatus>|\Inspirum\Balikobot\Model\Values\PackageStatus[]
187
     *
188
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
189
     */
190 5
    public function trackPackagesLastStatus(OrderedPackageCollection $packages): array
191
    {
192 5
        $response = $this->client->trackPackagesLastStatus($packages->getShipper(), $packages->getCarrierIds());
193
194 5
        $statuses = [];
195
196 5
        foreach ($response as $status) {
197 5
            $statuses[] = PackageStatus::newInstanceFromData($status);
198
        }
199
200 5
        return $statuses;
201
    }
202
203
    /**
204
     * Get overview for given shipper
205
     *
206
     * @param string $shipper
207
     *
208
     * @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[]
209
     *
210
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
211
     */
212 3
    public function getOverview(string $shipper): OrderedPackageCollection
213
    {
214 3
        $response = $this->client->getOverview($shipper);
215
216 3
        $response = $response['packages'];
217
218 3
        $orderedPackages = new OrderedPackageCollection();
219
220 3
        foreach ($response as $package) {
221 2
            $orderedPackage = OrderedPackage::newInstanceFromData($shipper, $package);
1 ignored issue
show
Documentation introduced by
$package is of type integer|string, but the function expects a array<string,*>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
222 2
            $orderedPackages->add($orderedPackage);
223
        }
224
225 3
        return $orderedPackages;
226
    }
227
228
    /**
229
     * Get labels for orders
230
     *
231
     * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages
232
     *
233
     * @return string
234
     *
235
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
236
     */
237 4
    public function getLabels(OrderedPackageCollection $packages): string
238
    {
239 4
        return $this->client->getLabels($packages->getShipper(), $packages->getPackageIds());
240
    }
241
242
    /**
243
     * Gets complete information about a package
244
     *
245
     * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package
246
     *
247
     * @return \Inspirum\Balikobot\Model\Values\Package
248
     *
249
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
250
     */
251 4
    public function getPackageInfo(OrderedPackage $package): Package
252
    {
253 4
        $response = $this->client->getPackageInfoByCarrierId($package->getShipper(), $package->getCarrierId());
254
255
        unset(
256 3
            $response['package_id'],
257 3
            $response['eshop_id'],
258 3
            $response['carrier_id'],
259 3
            $response['track_url'],
260 3
            $response['label_url'],
261 3
            $response['carrier_id_swap'],
262 3
            $response['pieces']
263
        );
264
265 3
        $options              = $response;
266 3
        $options[Option::EID] = $package->getBatchId();
267
268 3
        return new Package($options);
269
    }
270
271
    /**
272
     * Gets complete information about a package
273
     *
274
     * @param string $shipper
275
     * @param string $orderId
276
     *
277
     * @return \Inspirum\Balikobot\Model\Values\OrderedShipment
278
     *
279
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
280
     */
281 4
    public function getOrder(string $shipper, string $orderId): OrderedShipment
282
    {
283 4
        $response = $this->client->getOrder($shipper, $orderId);
284
285 3
        return OrderedShipment::newInstanceFromData($shipper, $response['package_ids'], $response);
286
    }
287
288
    /**
289
     * Returns available services for the given shipper
290
     *
291
     * @param string $shipper
292
     *
293
     * @return array<string,string>
294
     *
295
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
296
     */
297 6
    public function getServices(string $shipper): array
298
    {
299 6
        return $this->client->getServices($shipper);
300
    }
301
302
    /**
303
     * Returns available B2A services for the given shipper
304
     *
305
     * @param string $shipper
306
     *
307
     * @return array<string,string>
308
     *
309
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
310
     */
311 3
    public function getB2AServices(string $shipper): array
312
    {
313 3
        return $this->client->getB2AServices($shipper);
314
    }
315
316
    /**
317
     * Returns all manipulation units for the given shipper
318
     *
319
     * @param string $shipper
320
     * @param bool   $fullData
321
     *
322
     * @return array<string|array>
323
     *
324
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
325
     */
326 5
    public function getManipulationUnits(string $shipper, bool $fullData = false): array
327
    {
328 5
        return $this->client->getManipulationUnits($shipper, $fullData);
329
    }
330
331
    /**
332
     * Returns available manipulation units for the given shipper
333
     *
334
     * @param string $shipper
335
     * @param bool   $fullData
336
     *
337
     * @return array<string|array>
338
     *
339
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
340
     */
341 5
    public function getActivatedManipulationUnits(string $shipper, bool $fullData = false): array
342
    {
343 5
        return $this->client->getActivatedManipulationUnits($shipper, $fullData);
344
    }
345
346
    /**
347
     * Get all available branches
348
     *
349
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
350
     *
351
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
352
     */
353 1
    public function getBranches(): iterable
354
    {
355 1
        foreach ($this->getShippers() as $shipper) {
356 1
            yield from $this->getBranchesForShipper($shipper);
357
        }
358 1
    }
359
360
    /**
361
     * Get all available branches for countries
362
     *
363
     * @param array<string> $countries
364
     *
365
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
366
     *
367
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
368
     */
369 1
    public function getBranchesForCountries(array $countries): iterable
370
    {
371 1
        foreach ($this->getShippers() as $shipper) {
372 1
            yield from $this->getBranchesForShipperForCountries($shipper, $countries);
373
        }
374 1
    }
375
376
    /**
377
     * Get all available branches for given shipper
378
     *
379
     * @param string $shipper
380
     *
381
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
382
     *
383
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
384
     */
385 2
    public function getBranchesForShipper(string $shipper): iterable
386
    {
387 2
        foreach ($this->getServicesForShipper($shipper) as $service) {
388 2
            yield from $this->getBranchesForShipperService($shipper, $service);
389
        }
390 2
    }
391
392
    /**
393
     * Get all available branches for given shipper for countries
394
     *
395
     * @param string        $shipper
396
     * @param array<string> $countries
397
     *
398
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
399
     *
400
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
401
     */
402 2
    public function getBranchesForShipperForCountries(string $shipper, array $countries): iterable
403
    {
404 2
        foreach ($this->getServicesForShipper($shipper) as $service) {
405 2
            yield from $this->getBranchesForShipperServiceForCountries($shipper, $service, $countries);
406
        }
407 2
    }
408
409
    /**
410
     * Get services for shipper
411
     *
412
     * @param string $shipper
413
     *
414
     * @return array<string|null>
415
     *
416
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
417
     */
418 4
    private function getServicesForShipper(string $shipper): array
419
    {
420 4
        return array_keys($this->getServices($shipper)) ?: [null];
421
    }
422
423
    /**
424
     * Get all available branches for given shipper and service type for countries
425
     *
426
     * @param string        $shipper
427
     * @param string|null   $service
428
     * @param array<string> $countries
429
     *
430
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
431
     *
432
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
433
     */
434 3
    public function getBranchesForShipperServiceForCountries(
435
        string $shipper,
436
        ?string $service,
437
        array $countries
438
    ): iterable {
439 3
        foreach ($this->getAllBranchesForShipperServiceForCountries($shipper, $service, $countries) as $branch) {
440 3
            if (in_array($branch->getCountry(), $countries)) {
441 3
                yield $branch;
442
            }
443
        }
444 3
    }
445
446
    /**
447
     * Get all available branches for given shipper and service type filtered by countries if possible
448
     *
449
     * @param string        $shipper
450
     * @param string|null   $service
451
     * @param array<string> $countries
452
     *
453
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
454
     *
455
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
456
     */
457 3
    private function getAllBranchesForShipperServiceForCountries(
458
        string $shipper,
459
        ?string $service,
460
        array $countries
461
    ): iterable {
462 3
        if (Shipper::hasBranchCountryFilterSupport($shipper) === false) {
463 2
            return yield from $this->getBranchesForShipperService($shipper, $service);
464
        }
465
466 2
        foreach ($countries as $country) {
467 2
            yield from $this->getBranchesForShipperService($shipper, $service, $country);
468
        }
469 2
    }
470
471
    /**
472
     * Get all available branches for given shipper and service type
473
     *
474
     * @param string      $shipper
475
     * @param string|null $service
476
     * @param string|null $country
477
     *
478
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
479
     *
480
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
481
     */
482 7
    public function getBranchesForShipperService(string $shipper, ?string $service, string $country = null): iterable
483
    {
484 7
        $useFullBranchRequest = Shipper::hasFullBranchesSupport($shipper, $service);
485
486 7
        foreach ($this->client->getBranches($shipper, $service, $useFullBranchRequest, $country) as $branch) {
487 3
            yield Branch::newInstanceFromData($shipper, $service, $branch);
488
        }
489 6
    }
490
491
    /**
492
     * Get all available branches for given shipper
493
     *
494
     * @param string      $shipper
495
     * @param string      $country
496
     * @param string      $city
497
     * @param string|null $postcode
498
     * @param string|null $street
499
     * @param int|null    $maxResults
500
     * @param float|null  $radius
501
     * @param string|null $type
502
     *
503
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
504
     *
505
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
506
     */
507 5
    public function getBranchesForLocation(
508
        string $shipper,
509
        string $country,
510
        string $city,
511
        string $postcode = null,
512
        string $street = null,
513
        int $maxResults = null,
514
        float $radius = null,
515
        string $type = null
516
    ): iterable {
517 5
        $branches = $this->client->getBranchesForLocation(
518 5
            $shipper,
519
            $country,
520
            $city,
521
            $postcode,
522
            $street,
523
            $maxResults,
524
            $radius,
525
            $type
526
        );
527
528 4
        foreach ($branches as $branch) {
529 2
            yield Branch::newInstanceFromData($shipper, null, $branch);
530
        }
531 3
    }
532
533
    /**
534
     * Returns list of countries where service with cash-on-delivery payment type is available in
535
     *
536
     * @param string $shipper
537
     *
538
     * @return array<array<int|string,array<string,array>>>
539
     *
540
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
541
     */
542 3
    public function getCodCountries(string $shipper): array
543
    {
544 3
        return $this->client->getCodCountries($shipper);
545
    }
546
547
    /**
548
     * Returns list of countries where service is available in
549
     *
550
     * @param string $shipper
551
     *
552
     * @return array<array<int|string,string>>
553
     *
554
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
555
     */
556 3
    public function getCountries(string $shipper): array
557
    {
558 3
        return $this->client->getCountries($shipper);
559
    }
560
561
    /**
562
     * Returns available branches for the given shipper and its service
563
     *
564
     * @param string      $shipper
565
     * @param string      $service
566
     * @param string|null $country
567
     *
568
     * @return \Generator|\Inspirum\Balikobot\Model\Values\PostCode[]
569
     *
570
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
571
     */
572 3
    public function getPostCodes(string $shipper, string $service, string $country = null): iterable
573
    {
574 3
        foreach ($this->client->getPostCodes($shipper, $service, $country) as $postcode) {
575 2
            yield PostCode::newInstanceFromData($shipper, $service, $postcode);
576
        }
577 2
    }
578
579
    /**
580
     * Check package(s) data
581
     *
582
     * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages
583
     *
584
     * @return void
585
     *
586
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
587
     */
588 3
    public function checkPackages(PackageCollection $packages): void
589
    {
590 3
        $this->client->checkPackages($packages->getShipper(), $packages->toArray());
591 2
    }
592
593
    /**
594
     * Returns available manipulation units for the given shipper
595
     *
596
     * @param string $shipper
597
     * @param bool   $fullData
598
     *
599
     * @return array<string|array>
600
     *
601
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
602
     */
603 5
    public function getAdrUnits(string $shipper, bool $fullData = false): array
604
    {
605 5
        return $this->client->getAdrUnits($shipper, $fullData);
606
    }
607
608
    /**
609
     * Returns available activated services for the given shipper
610
     *
611
     * @param string $shipper
612
     *
613
     * @return array<string,mixed>
614
     *
615
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
616
     */
617 3
    public function getActivatedServices(string $shipper): array
618
    {
619 3
        return $this->client->getActivatedServices($shipper);
620
    }
621
622
    /**
623
     * Order shipments from place B (typically supplier / previous consignee) to place A (shipping point)
624
     *
625
     * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages
626
     *
627
     * @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[]
628
     *
629
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
630
     */
631 5
    public function orderB2AShipment(PackageCollection $packages): OrderedPackageCollection
632
    {
633 5
        $response = $this->client->orderB2AShipment($packages->getShipper(), $packages->toArray());
634
635 4
        $orderedPackages = new OrderedPackageCollection();
636
637 4
        foreach ($response as $i => $package) {
638 4
            $package['eid'] = (string) $packages->offsetGet($i)->getEID();
639 4
            $orderedPackage = OrderedPackage::newInstanceFromData($packages->getShipper(), $package);
640 4
            $orderedPackages->add($orderedPackage);
641
        }
642
643 4
        return $orderedPackages;
644
    }
645
646
    /**
647
     * Get PDF link with signed consignment delivery document by the recipient
648
     *
649
     * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package
650
     *
651
     * @return string
652
     *
653
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
654
     */
655 2
    public function getProofOfDelivery(OrderedPackage $package): string
656
    {
657 2
        $packages = new OrderedPackageCollection();
658 2
        $packages->add($package);
659
660 2
        return $this->getProofOfDeliveries($packages)[0];
661
    }
662
663
    /**
664
     * Get array of PDF links with signed consignment delivery document by the recipient
665
     *
666
     * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages
667
     *
668
     * @return array<string>
669
     *
670
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
671
     */
672 6
    public function getProofOfDeliveries(OrderedPackageCollection $packages): array
673
    {
674 6
        return $this->client->getProofOfDeliveries($packages->getShipper(), $packages->getCarrierIds());
675
    }
676
677
    /**
678
     * Obtain the price of carriage at consignment level
679
     *
680
     * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages
681
     *
682
     * @return \Inspirum\Balikobot\Model\Aggregates\PackageTransportCostCollection|\Inspirum\Balikobot\Model\Values\PackageTransportCost[]
683
     *
684
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
685
     */
686 4
    public function getTransportCosts(PackageCollection $packages): PackageTransportCostCollection
687
    {
688 4
        $response = $this->client->getTransportCosts($packages->getShipper(), $packages->toArray());
689
690 3
        $transportCosts = new PackageTransportCostCollection($packages->getShipper());
691
692 3
        foreach ($response as $i => $package) {
693 3
            $transportCost = PackageTransportCost::newInstanceFromData($packages->getShipper(), $package);
694 3
            $transportCosts->add($transportCost);
695
        }
696
697 3
        return $transportCosts;
698
    }
699
700
    /**
701
     * Get information on individual countries of the world
702
     *
703
     * @return array<string,\Inspirum\Balikobot\Model\Values\Country>|\Inspirum\Balikobot\Model\Values\Country[]
704
     *
705
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
706
     */
707 3
    public function getCountriesData(): array
708
    {
709 3
        $response = $this->client->getCountriesData();
710
711 3
        $countries = [];
712
713 3
        foreach ($response as $code => $country) {
714 2
            $countries[$code] = Country::newInstanceFromData($country);
715
        }
716
717 3
        return $countries;
718
    }
719
720
    /**
721
     * Method for obtaining news in the Balikobot API
722
     *
723
     * @return array<string,mixed>
724
     *
725
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
726
     */
727
    public function getChangelog(): array
728
    {
729
        return $this->client->getChangelog();
730
    }
731
}
732