|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Inspirum\Balikobot\Model\TransportCost; |
|
6
|
|
|
|
|
7
|
|
|
use Inspirum\Arrayable\BaseModel; |
|
8
|
|
|
use function array_map; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @extends \Inspirum\Arrayable\BaseModel<string,mixed> |
|
12
|
|
|
*/ |
|
13
|
|
|
final class DefaultTransportCost extends BaseModel implements TransportCost |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @param array<\Inspirum\Balikobot\Model\TransportCost\TransportCostPart> $costsBreakdown |
|
17
|
|
|
*/ |
|
18
|
5 |
|
public function __construct( |
|
19
|
|
|
private readonly string $batchId, |
|
20
|
|
|
private readonly string $carrier, |
|
21
|
|
|
private readonly float $totalCost, |
|
22
|
|
|
private readonly string $currencyCode, |
|
23
|
|
|
private readonly array $costsBreakdown = [], |
|
24
|
|
|
) { |
|
25
|
5 |
|
} |
|
26
|
|
|
|
|
27
|
2 |
|
public function getBatchId(): string |
|
28
|
|
|
{ |
|
29
|
2 |
|
return $this->batchId; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
1 |
|
public function getCarrier(): string |
|
33
|
|
|
{ |
|
34
|
1 |
|
return $this->carrier; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
3 |
|
public function getTotalCost(): float |
|
38
|
|
|
{ |
|
39
|
3 |
|
return $this->totalCost; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
3 |
|
public function getCurrencyCode(): string |
|
43
|
|
|
{ |
|
44
|
3 |
|
return $this->currencyCode; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** @inheritDoc */ |
|
48
|
1 |
|
public function getCostsBreakdown(): array |
|
49
|
|
|
{ |
|
50
|
1 |
|
return $this->costsBreakdown; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return array<string,mixed> |
|
55
|
|
|
*/ |
|
56
|
2 |
|
public function __toArray(): array |
|
57
|
|
|
{ |
|
58
|
2 |
|
return [ |
|
|
|
|
|
|
59
|
2 |
|
'batchId' => $this->batchId, |
|
60
|
2 |
|
'carrier' => $this->carrier, |
|
61
|
2 |
|
'totalCost' => $this->totalCost, |
|
62
|
2 |
|
'currencyCode' => $this->currencyCode, |
|
63
|
2 |
|
'costsBreakdown' => array_map(static fn (TransportCostPart $costPart): array => $costPart->__toArray(), $this->costsBreakdown), |
|
64
|
2 |
|
]; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: