Passed
Push — master ( cedc1b...f07611 )
by Jhao
03:07
created

Address::setCountry()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Appwilio\RussianPostSDK\Dispatching\Entities;
6
7
use Appwilio\RussianPostSDK\Dispatching\Instantiator;
8
use Appwilio\RussianPostSDK\Dispatching\Enum\Country;
9
use Appwilio\RussianPostSDK\Dispatching\Enum\AddressType;
10
use Appwilio\RussianPostSDK\Dispatching\Contracts\Arrayable;
11
use Appwilio\RussianPostSDK\Dispatching\Endpoints\Services\Entities\NormalizedAddress;
12
13
final class Address extends AbstractAddress implements Arrayable
14
{
15
    public static function fromNormalizedAddress(NormalizedAddress $address): self
16
    {
17
        if ($address->isUnuseful()) {
18
            throw new \InvalidArgumentException('У нормализованного адреса неприемлемое качество.');
19
        }
20
21
        return Instantiator::instantiateFrom(self::class, $address, [
22
            'id', 'original-address', 'quality-code', 'validation-code'
23
        ]);
24
    }
25
26
    public function __construct(?AddressType $type = null)
27
    {
28
        $this->setType($type ?? AddressType::DEFAULT());
29
    }
30
31
    public function setType(AddressType $type)
32
    {
33
        $this->data['address-type'] = $type;
34
35
        return $this;
36
    }
37
38
    public function getAddressType(): string
39
    {
40
        return $this->get('address-type');
41
    }
42
43
    public function getCountryCode(): ?string
44
    {
45
        return $this->get('mail-direct');
46
    }
47
48
    public function setCountry(Country $country)
49
    {
50
        $this->data['mail-direct'] = $country;
51
52
        return $this;
53
    }
54
55
    public function setIndex(string $index)
56
    {
57
        $this->data['index'] = $index;
58
59
        return $this;
60
    }
61
62
    public function setArea(string $area)
63
    {
64
        $this->data['area'] = $area;
65
66
        return $this;
67
    }
68
69
    public function setPlace(string $place)
70
    {
71
        $this->data['place'] = $place;
72
73
        return $this;
74
    }
75
76
    public function setRegion(string $region)
77
    {
78
        $this->data['region'] = $region;
79
80
        return $this;
81
    }
82
83
    public function setLocation(string $location)
84
    {
85
        $this->data['location'] = $location;
86
87
        return $this;
88
    }
89
90
    public function setStreet(string $street)
91
    {
92
        $this->data['street'] = $street;
93
94
        return $this;
95
    }
96
97
    public function setHouse(string $house)
98
    {
99
        $this->data['house'] = $house;
100
101
        return $this;
102
    }
103
104
    public function setRoom(string $room)
105
    {
106
        $this->data['room'] = $room;
107
108
        return $this;
109
    }
110
111
    public function setSlash(string $slash)
112
    {
113
        $this->data['slash'] = $slash;
114
115
        return $this;
116
    }
117
118
    public function setBuilding(string $building)
119
    {
120
        $this->data['building'] = $building;
121
122
        return $this;
123
    }
124
125
    public function setCorpus(string $corpus)
126
    {
127
        $this->data['corpus'] = $corpus;
128
129
        return $this;
130
    }
131
132
    public function setLetter(string $letter)
133
    {
134
        $this->data['letter'] = $letter;
135
136
        return $this;
137
    }
138
139
    public function setHotel(string $hotel)
140
    {
141
        $this->data['hotel'] = $hotel;
142
143
        return $this;
144
    }
145
146
    public function getVladenie(): ?string
147
    {
148
        return $this->get('vladenie');
149
    }
150
151
    public function setVladenie(string $vladenie)
152
    {
153
        $this->data['vladenie'] = $vladenie;
154
155
        return $this;
156
    }
157
158
    public function toArray(): array
159
    {
160
        return $this->data;
161
    }
162
}
163