Passed
Push — master ( 65a6b4...cbdbb3 )
by Jhao
02:03
created

NormalizedAddress::getIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\Entities\AbstractAddress;
17
18
final class NormalizedAddress extends AbstractAddress
19
{
20
    /**
21
     * Коды качества нормализации адреса.
22
     *
23
     * @see https://otpravka.pochta.ru/specification#/enums-clean-address-quality
24
     */
25
    public const QUALITY_GOOD = 'GOOD';
26
    public const QUALITY_ON_DEMAND = 'ON_DEMAND';
27
    public const QUALITY_POSTAL_BOX = 'POSTAL_BOX';
28
    public const QUALITY_UNDEF_01 = 'UNDEF_01';
29
    public const QUALITY_UNDEF_02 = 'UNDEF_02';
30
    public const QUALITY_UNDEF_03 = 'UNDEF_03';
31
    public const QUALITY_UNDEF_04 = 'UNDEF_04';
32
    public const QUALITY_UNDEF_05 = 'UNDEF_05';
33
    public const QUALITY_UNDEF_06 = 'UNDEF_06';
34
    public const QUALITY_UNDEF_07 = 'UNDEF_07';
35
36
    /**
37
     * Коды проверки нормализации адреса.
38
     *
39
     * @https://otpravka.pochta.ru/specification#/enums-clean-address-validation
40
     */
41
    public const VALIDATION_VALIDATED = 'VALIDATED';
42
    public const VALIDATION_OVERRIDDEN = 'OVERRIDDEN';
43
    public const VALIDATION_CONFIRMED_MANUALLY = 'CONFIRMED_MANUALLY';
44
45
    public const ACCEPTABLE_QUALITY = [
46
        self::QUALITY_GOOD, self::QUALITY_POSTAL_BOX, self::QUALITY_ON_DEMAND, self::QUALITY_UNDEF_05,
47
    ];
48
49
    public const ACCEPTABLE_VALIDITY = [
50
        self::VALIDATION_VALIDATED, self::VALIDATION_OVERRIDDEN, self::VALIDATION_CONFIRMED_MANUALLY,
51
    ];
52
53 1
    public function getId(): string
54
    {
55 1
        return $this->get('id');
56
    }
57
58 1
    public function getOriginalAddress(): string
59
    {
60 1
        return $this->get('original-address');
61
    }
62
63 1
    public function getAddressType(): string
64
    {
65 1
        return $this->get('address-type');
66
    }
67
68 13
    public function getQualityCode(): string
69
    {
70 13
        return $this->get('quality-code');
71
    }
72
73 13
    public function getValidationCode(): string
74
    {
75 13
        return $this->get('validation-code');
76
    }
77
78 12
    public function isUseful(): bool
79
    {
80 12
        $quality = \in_array($this->getQualityCode(), self::ACCEPTABLE_QUALITY);
81 12
        $validity = \in_array($this->getValidationCode(), self::ACCEPTABLE_VALIDITY);
82
83 12
        return $quality && $validity;
84
    }
85
86 12
    public function isUnuseful(): bool
87
    {
88 12
        return ! $this->isUseful();
89
    }
90
}
91