Passed
Push — master ( 263c14...2fa329 )
by Jhao
02:31
created

Batch::getPostofficeCode()   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 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
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
/**
4
 * This file is part of RussianPost SDK package.
5
 *
6
 * © Appwilio (http://appwilio.com), greabock (https://github.com/greabock), 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\Batches\Entites;
15
16
use Appwilio\RussianPostSDK\Dispatching\DataAware;
17
use Appwilio\RussianPostSDK\Dispatching\Entities\Tariff;
18
use Appwilio\RussianPostSDK\Dispatching\Enum\BatchStatus;
19
use Appwilio\RussianPostSDK\Dispatching\Enum\MailCategory;
20
use Appwilio\RussianPostSDK\Dispatching\Enum\MailRank;
21
use Appwilio\RussianPostSDK\Dispatching\Enum\MailType;
22
use Appwilio\RussianPostSDK\Dispatching\Enum\NotifyCategory;
23
use Appwilio\RussianPostSDK\Dispatching\Enum\PaymentMethodType;
24
use Appwilio\RussianPostSDK\Dispatching\Enum\TransportType;
25
use Appwilio\RussianPostSDK\Dispatching\Instantiator;
26
27
final class Batch
28
{
29
    use DataAware;
30
31
    /**
32
     * Имя (номер) партии.
33
     *
34
     * @return string
35
     */
36
    public function getName(): string
37
    {
38
        return (string) $this->get('batch-name');
39
    }
40
41
    /**
42
     * Количество заказов в партии.
43
     *
44
     * @return int
45
     */
46
    public function getShipmentCount(): int
47
    {
48
        return (int) $this->get('shipment-count');
49
    }
50
51
    /**
52
     * Общий вес в граммах.
53
     *
54
     * @return int
55
     */
56
    public function getShipmentMass()
57
    {
58
        return (int) $this->get('shipment-mass');
59
    }
60
61
    /**
62
     * Статус партии.
63
     *
64
     * @return BatchStatus
65
     */
66
    public function getStatus(): BatchStatus
67
    {
68
        return new BatchStatus($this->get('batch-status'));
69
    }
70
71
    /**
72
     * Дата обновления статуса партии.
73
     *
74
     * @return \DateTimeInterface
75
     */
76
    public function getStatusDate(): \DateTimeInterface
77
    {
78
        return \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.???P', $this->get('batch-status-date'));
79
    }
80
81
    /**
82
     * Идентификатор подразделения.
83
     *
84
     * @return string
85
     */
86
    public function getBranchName(): string
87
    {
88
        return $this->get('branch-name');
89
    }
90
91
    /**
92
     * Виды РПО в партии.
93
     *
94
     * @return MailType[]
95
     */
96
    public function getMailTypes()
97
    {
98
        return $this->get('combined-batch-mail-types');
99
    }
100
101
    /**
102
     * Плата за услугу "Курьерский сбор".
103
     *
104
     * @return Tariff
105
     */
106
    public function getCourierCallRate(): Tariff
107
    {
108
        return Instantiator::instantiate(Tariff::class, [
109
            'rate' => $this->get('courier-call-rate-wo-vat'),
110
            'vat'  => $this->get('courier-call-rate-with-vat') - $this->get('courier-call-rate-wo-vat'),
111
        ]);
112
    }
113
114
    /**
115
     * Статусы заявки на вызов курьера.
116
     *
117
     * @return mixed|null
118
     */
119
    public function getCourierOrderStatuses()
120
    {
121
        return $this->get('courier-order-statuses');
122
    }
123
124
    /**
125
     * Способ оплаты уведомления о вручении РПО.
126
     *
127
     * @return string
128
     */
129
    public function getDeliveryNoticePaymentMethod()
130
    {
131
        return $this->get('delivery-notice-payment-method');
132
    }
133
134
    /**
135
     * Признак международной почты.
136
     *
137
     * @return bool
138
     */
139
    public function isInternational(): bool
140
    {
141
        return $this->get('international', 'bool');
142
    }
143
144
    /**
145
     * Номер документа для сдачи партии.
146
     *
147
     * @return int
148
     */
149
    public function getListNumber(): int
150
    {
151
        return (int) $this->get('list-number');
152
    }
153
154
    /**
155
     * Дата документа для сдачи партии (yyyy-MM-dd).
156
     *
157
     * @return \DateTimeInterface
158
     */
159
    public function getListNumberDate(): \DateTimeInterface
160
    {
161
        return \DateTimeImmutable::createFromFormat('Y-m-d', $this->get('list-number-date'));
162
    }
163
164
    /**
165
     * Категория РПО.
166
     *
167
     * @return MailCategory
168
     */
169
    public function getMailCategory(): MailCategory
170
    {
171
        return new MailCategory($this->get('mail-category'));
172
    }
173
174
    /**
175
     * Категория РПО (текст).
176
     *
177
     * @return string
178
     */
179
    public function getMailCategoryText()
180
    {
181
        // FIXME
182
        return $this->get('mail-category-text');
183
    }
184
185
    /**
186
     * Разряд писем в партии.
187
     *
188
     * @return MailRank
189
     */
190
    public function getMailRank(): MailRank
191
    {
192
        return new MailRank($this->get('mail-rank'));
193
    }
194
195
    /**
196
     * Вид РПО.
197
     *
198
     * @return MailType
199
     */
200
    public function getMailType(): MailType
201
    {
202
        return new MailType($this->get('mail-type'));
203
    }
204
205
    /**
206
     * Вид РПО (текст).
207
     *
208
     * @return string
209
     */
210
    public function getMailTypeText()
211
    {
212
        // FIXME
213
        return $this->get('mail-type-text');
214
    }
215
216
    /**
217
     * Способ оплаты.
218
     *
219
     * @return PaymentMethodType
220
     */
221
    public function getPaymentMethod(): PaymentMethodType
222
    {
223
        return new PaymentMethodType($this->get('payment-method'));
224
    }
225
226
    /**
227
     * Способ оплаты уведомлений.
228
     *
229
     * @return PaymentMethodType
230
     */
231
    public function getNoticePaymentMethod(): PaymentMethodType
232
    {
233
        return new PaymentMethodType($this->get('notice-payment-method'));
234
    }
235
236
    /**
237
     * Коды отметок внутренних и международных отправлений.
238
     *
239
     * @return string[]
240
     */
241
    public function getPostmarks()
242
    {
243
        // FIXME: сделать enum
244
        return $this->get('postmarks');
245
    }
246
247
    /**
248
     * Адрес места приема.
249
     *
250
     * @return string
251
     */
252
    public function getPostofficeAddress(): string
253
    {
254
        return $this->get('postoffice-address');
255
    }
256
257
    /**
258
     * Индекс места приема.
259
     *
260
     * @return string
261
     */
262
    public function getPostofficeCode(): string
263
    {
264
        return $this->get('postoffice-code');
265
    }
266
267
    /**
268
     * Наименование места приема.
269
     *
270
     * @return string
271
     */
272
    public function getPostofficeName(): string
273
    {
274
        return $this->get('postoffice-name');
275
    }
276
277
    /**
278
     * Плата за авиа пересылку.
279
     *
280
     * @return Tariff
281
     */
282
    public function getShipmentAviaRate(): Tariff
283
    {
284
        return Instantiator::instantiate(Tariff::class, [
285
            'rate' => $this->get('shipment-avia-rate-sum'),
286
            'vat'  => $this->get('shipment-avia-rate-vat-sum'),
287
        ]);
288
    }
289
290
    /**
291
     * Плата за проверку комплектности.
292
     *
293
     * @return Tariff
294
     */
295
    public function getShipmentCompletenessCheckingRateSum(): Tariff
296
    {
297
        return Instantiator::instantiate(Tariff::class, [
298
            'rate' => $this->get('shipment-completeness-checking-rate-sum'),
299
            'vat'  => $this->get('shipment-completeness-checking-rate-vat-sum'),
300
        ]);
301
    }
302
303
    /**
304
     * Плата за проверку вложений.
305
     *
306
     * @return Tariff
307
     */
308
    public function getShipmentContentsCheckingRate(): Tariff
309
    {
310
        return Instantiator::instantiate(Tariff::class, [
311
            'rate' => $this->get('shipment-contents-checking-rate-sum'),
312
            'vat'  => $this->get('shipment-contents-checking-rate-vat-sum'),
313
        ]);
314
    }
315
316
    /**
317
     * Плата за наземную пересылку.
318
     *
319
     * @return Tariff
320
     */
321
    public function getShipmentGroundRateSum(): Tariff
322
    {
323
        return Instantiator::instantiate(Tariff::class, [
324
            'rate' => $this->get('shipment-ground-rate-sum'),
325
            'vat'  => $this->get('shipment-ground-rate-vat-sum'),
326
        ]);
327
    }
328
329
    /**
330
     * Плата за объявленную ценность.
331
     *
332
     * @return Tariff
333
     */
334
    public function getShipmentInsureRateSum(): Tariff
335
    {
336
        return Instantiator::instantiate(Tariff::class, [
337
            'rate' => $this->get('shipment-insure-rate-sum'),
338
            'vat'  => $this->get('shipment-insure-rate-vat-sum'),
339
        ]);
340
    }
341
342
    /**
343
     * Плата за опись вложения.
344
     *
345
     * @return Tariff
346
     */
347
    public function getShipmentInventoryRateSum(): Tariff
348
    {
349
        return Instantiator::instantiate(Tariff::class, [
350
            'rate' => $this->get('shipment-inventory-rate-sum'),
351
            'vat'  => $this->get('shipment-inventory-rate-vat-sum'),
352
        ]);
353
    }
354
355
    /**
356
     * Плата за пересылку.
357
     *
358
     * @return Tariff
359
     */
360
    public function getShipmentMassRateSum(): Tariff
361
    {
362
        return Instantiator::instantiate(Tariff::class, [
363
            'rate' => $this->get('shipment-mass-rate-sum'),
364
            'vat'  => $this->get('shipment-mass-rate-vat-sum'),
365
        ]);
366
    }
367
368
    /**
369
     * Плата за уведомление о вручении.
370
     *
371
     * @return Tariff
372
     */
373
    public function getShipmentNoticeRateSum(): Tariff
374
    {
375
        return Instantiator::instantiate(Tariff::class, [
376
            'rate' => $this->get('shipment-notice-rate-sum'),
377
            'vat'  => $this->get('shipment-notice-rate-vat-sum'),
378
        ]);
379
    }
380
381
    /**
382
     * Плата за смс нотификацию в копейках.
383
     *
384
     * @return Tariff
385
     */
386
    public function getShipmentSmsRateSum(): Tariff
387
    {
388
        return Instantiator::instantiate(Tariff::class, [
389
            'rate' => $this->get('shipment-sms-rate-sum'),
390
            'vat'  => $this->get('shipment-sms-rate-vat-sum'),
391
        ]);
392
    }
393
394
    /**
395
     * Категория уведомления о вручении РПО.
396
     *
397
     * @return NotifyCategory
398
     */
399
    public function getShippingNoticeType(): NotifyCategory
400
    {
401
        return new NotifyCategory($this->get('shipping-notice-type'));
402
    }
403
404
    /**
405
     * Вид транспортировки.
406
     *
407
     * @return TransportType
408
     */
409
    public function getTransportType(): TransportType
410
    {
411
        return new TransportType($this->get('transport-type'));
412
    }
413
414
    /**
415
     * Признак использования онлайн-баланса.
416
     *
417
     * @return bool
418
     */
419
    public function isOnlineBalanceUsed(): bool
420
    {
421
        return $this->get('use-online-balance', 'bool');
422
    }
423
424
    /**
425
     * Без указания массы.
426
     *
427
     * @return bool
428
     */
429
    public function isWithoutMass(): bool
430
    {
431
        return $this->get('wo-mass', 'bool');
432
    }
433
}
434