Passed
Push — master ( 2cdaae...14b6d5 )
by Jhao
02:25
created

Order::getFiscalData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Appwilio\RussianPostSDK\Dispatching\Endpoints\Orders\Entites;
6
7
use Appwilio\RussianPostSDK\Core\ArrayOf;
8
use Appwilio\RussianPostSDK\Dispatching\DataAware;
9
use Appwilio\RussianPostSDK\Dispatching\Instantiator;
10
use Appwilio\RussianPostSDK\Dispatching\Entities\Tariff;
11
use Appwilio\RussianPostSDK\Dispatching\Entities\Address;
12
use Appwilio\RussianPostSDK\Dispatching\Entities\DeliveryTime;
13
14
final class Order
15
{
16
    use DataAware;
17
18
    public function getId(): string
19
    {
20
        return (string) $this->get('id');
21
    }
22
23
    public function getNumber(): string
24
    {
25
        return $this->get('order-num');
26
    }
27
28
    public function getWeight(): int
29
    {
30
        return $this->get('mass');
31
    }
32
33
    public function getTrackingNumber(): string
34
    {
35
        return $this->get('barcode');
36
    }
37
38
    public function hasCustomsDeclaration(): bool
39
    {
40
        return (bool) $this->get('customs-declaration');
41
    }
42
43
    public function getCustomsDeclaration(): ?CustomsDeclaration
44
    {
45
        return Instantiator::instantiate(CustomsDeclaration::class, $this->get('customs-declaration'));
46
    }
47
48
    /**
49
     * @return OrderItem[]|null
50
     */
51
    public function getItems()
52
    {
53
        return Instantiator::instantiate(new ArrayOf(OrderItem::class), $this->get('goods'));
54
    }
55
56
    public function getAddress(): Address
57
    {
58
        return Instantiator::instantiate(Address::class, [
59
            'address-type-to'     => $this->get('address-type-to'),
60
            'area-to'             => $this->get('area-to'),
61
            'building-to'         => $this->get('building-to'),
62
            'corpus-to'           => $this->get('corpus-to'),
63
            'hotel-to'            => $this->get('hotel-to'),
64
            'house-to'            => $this->get('house-to'),
65
            'letter-to'           => $this->get('letter-to'),
66
            'location-to'         => $this->get('location-to'),
67
            'office-to'           => $this->get('office-to'),
68
            'place-to'            => $this->get('place-to'),
69
            'region-to'           => $this->get('region-to'),
70
            'room-to'             => $this->get('room-to'),
71
            'slash-to'            => $this->get('slash-to'),
72
            'street-to'           => $this->get('street-to'),
73
            'mail-direct'         => $this->get('mail-direct'),
74
            'num-address-type-to' => $this->get('num-address-type-to'),
75
            'index-to'            => $this->data['index-to'] ?? $this->data['str-index-to'],
76
        ]);
77
    }
78
79
    public function getRecipient(): Recipient
80
    {
81
        return Instantiator::instantiate(Recipient::class, [
82
            'given-name'     => $this->get('given-name'),
83
            'middle-name'    => $this->get('middle-name'),
84
            'surname'        => $this->get('surname'),
85
            'tel-address'    => $this->get('tel-address'),
86
            'recipient-name' => $this->get('recipient-name'),
87
        ]);
88
    }
89
90
    public function getDeliveryTime(): ?DeliveryTime
91
    {
92
        return Instantiator::instantiate(DeliveryTime::class, $this->get('delivery-time'));
93
    }
94
95
    public function getGroundRate(): Tariff
96
    {
97
        return Instantiator::instantiate(Tariff::class, [
98
            'rate' => $this->get('ground-rate-wo-vat'),
99
            'vat' => $this->get('ground-vat'),
100
        ]);
101
    }
102
103
    public function getInsuranceRate(): Tariff
104
    {
105
        return Instantiator::instantiate(Tariff::class, [
106
            'rate' => $this->get('insr-rate-wo-vat'),
107
            'vat' => $this->get('insr-rate-with-vat') - $this->get('insr-rate-wo-vat'),
108
        ]);
109
    }
110
111
    public function getTotalRate(): Tariff
112
    {
113
        return Instantiator::instantiate(Tariff::class, [
114
            'rate' => $this->get('total-rate-wo-vat'),
115
            'vat' => $this->get('total-vat'),
116
        ]);
117
    }
118
119
    public function getEcomData(): ?EcomData
120
    {
121
        return Instantiator::instantiate(EcomData::class, $this->get('ecom-data'));
122
    }
123
124
    public function getFiscalData(): ?FiscalData
125
    {
126
        return Instantiator::instantiate(FiscalData::class, $this->get('fiscal-data'));
127
    }
128
}
129