Passed
Push — master ( 7eb449...cf8d88 )
by Jhao
02:24
created

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