|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of RussianPost SDK package. |
|
5
|
|
|
* |
|
6
|
|
|
* © Appwilio (http://appwilio.com), JhaoDa (https://github.com/jhaoda) |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Appwilio\RussianPostSDK\Dispatching\Endpoints\Services\Entities; |
|
15
|
|
|
|
|
16
|
|
|
use Appwilio\RussianPostSDK\Dispatching\DataAware; |
|
17
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Contracts\Arrayable; |
|
18
|
|
|
|
|
19
|
|
|
final class NormalizedAddress implements Arrayable |
|
20
|
|
|
{ |
|
21
|
|
|
use DataAware; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Коды качества нормализации адреса. |
|
25
|
|
|
* |
|
26
|
|
|
* @see https://otpravka.pochta.ru/specification#/enums-clean-address-quality |
|
27
|
|
|
*/ |
|
28
|
|
|
public const QUALITY_GOOD = 'GOOD'; |
|
29
|
|
|
public const QUALITY_ON_DEMAND = 'ON_DEMAND'; |
|
30
|
|
|
public const QUALITY_POSTAL_BOX = 'POSTAL_BOX'; |
|
31
|
|
|
public const QUALITY_UNDEF_01 = 'UNDEF_01'; |
|
32
|
|
|
public const QUALITY_UNDEF_02 = 'UNDEF_02'; |
|
33
|
|
|
public const QUALITY_UNDEF_03 = 'UNDEF_03'; |
|
34
|
|
|
public const QUALITY_UNDEF_04 = 'UNDEF_04'; |
|
35
|
|
|
public const QUALITY_UNDEF_05 = 'UNDEF_05'; |
|
36
|
|
|
public const QUALITY_UNDEF_06 = 'UNDEF_06'; |
|
37
|
|
|
public const QUALITY_UNDEF_07 = 'UNDEF_07'; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Коды проверки нормализации адреса. |
|
41
|
|
|
* |
|
42
|
|
|
* @https://otpravka.pochta.ru/specification#/enums-clean-address-validation |
|
43
|
|
|
*/ |
|
44
|
|
|
public const VALIDATION_VALIDATED = 'VALIDATED'; |
|
45
|
|
|
public const VALIDATION_OVERRIDDEN = 'OVERRIDDEN'; |
|
46
|
|
|
public const VALIDATION_CONFIRMED_MANUALLY = 'CONFIRMED_MANUALLY'; |
|
47
|
|
|
|
|
48
|
|
|
public const ACCEPTABLE_QUALITY = [ |
|
49
|
|
|
self::QUALITY_GOOD, self::QUALITY_POSTAL_BOX, self::QUALITY_ON_DEMAND, self::QUALITY_UNDEF_05, |
|
50
|
|
|
]; |
|
51
|
|
|
|
|
52
|
|
|
public const ACCEPTABLE_VALIDITY = [ |
|
53
|
|
|
self::VALIDATION_VALIDATED, self::VALIDATION_OVERRIDDEN, self::VALIDATION_CONFIRMED_MANUALLY, |
|
54
|
|
|
]; |
|
55
|
|
|
|
|
56
|
1 |
|
public function getId(): string |
|
57
|
|
|
{ |
|
58
|
1 |
|
return $this->get('id'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
1 |
|
public function getIndex(): ?string |
|
62
|
|
|
{ |
|
63
|
1 |
|
return $this->get('index'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
1 |
|
public function getArea(): ?string |
|
67
|
|
|
{ |
|
68
|
1 |
|
return $this->get('area'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
public function getPlace(): ?string |
|
72
|
|
|
{ |
|
73
|
1 |
|
return $this->get('place'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
1 |
|
public function getRegion(): ?string |
|
77
|
|
|
{ |
|
78
|
1 |
|
return $this->get('region'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
1 |
|
public function getLocation(): ?string |
|
82
|
|
|
{ |
|
83
|
1 |
|
return $this->get('location'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
1 |
|
public function getStreet(): ?string |
|
87
|
|
|
{ |
|
88
|
1 |
|
return $this->get('street'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
1 |
|
public function getHouse(): ?string |
|
92
|
|
|
{ |
|
93
|
1 |
|
return $this->get('house'); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
1 |
|
public function getRoom(): ?string |
|
97
|
|
|
{ |
|
98
|
1 |
|
return $this->get('room'); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
1 |
|
public function getSlash(): ?string |
|
102
|
|
|
{ |
|
103
|
1 |
|
return $this->get('slash'); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
1 |
|
public function getBuilding(): ?string |
|
107
|
|
|
{ |
|
108
|
1 |
|
return $this->get('building'); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
1 |
|
public function getCorpus(): ?string |
|
112
|
|
|
{ |
|
113
|
1 |
|
return $this->get('corpus'); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
1 |
|
public function getLetter(): ?string |
|
117
|
|
|
{ |
|
118
|
1 |
|
return $this->get('letter'); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
1 |
|
public function getHotel(): ?string |
|
122
|
|
|
{ |
|
123
|
1 |
|
return $this->get('hotel'); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
1 |
|
public function getNumAddressType(): ?string |
|
127
|
|
|
{ |
|
128
|
1 |
|
return $this->get('num-address-type'); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
1 |
|
public function getOriginalAddress(): string |
|
132
|
|
|
{ |
|
133
|
1 |
|
return $this->get('original-address'); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
1 |
|
public function getAddressType(): string |
|
137
|
|
|
{ |
|
138
|
1 |
|
return $this->get('address-type'); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
13 |
|
public function getQualityCode(): string |
|
142
|
|
|
{ |
|
143
|
13 |
|
return $this->get('quality-code'); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
13 |
|
public function getValidationCode(): string |
|
147
|
|
|
{ |
|
148
|
13 |
|
return $this->get('validation-code'); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
12 |
|
public function isUseful(): bool |
|
152
|
|
|
{ |
|
153
|
12 |
|
$quality = \in_array($this->getQualityCode(), self::ACCEPTABLE_QUALITY); |
|
154
|
12 |
|
$validity = \in_array($this->getValidationCode(), self::ACCEPTABLE_VALIDITY); |
|
155
|
|
|
|
|
156
|
12 |
|
return $quality && $validity; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
12 |
|
public function isUnuseful(): bool |
|
160
|
|
|
{ |
|
161
|
12 |
|
return ! $this->isUseful(); |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|