Value   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 25
dl 0
loc 122
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setValue() 0 4 1
A setEnum() 0 5 1
A __construct() 0 5 1
A getValue() 0 3 1
A loadInRaw() 0 9 3
A getEnum() 0 3 1
A getSubtype() 0 3 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: DrillCoder
5
 * Date: 10.09.17
6
 * Time: 21:20
7
 */
8
9
namespace DrillCoder\AmoCRM_Wrap\Helpers;
10
11
/**
12
 * Class Value
13
 * @package DrillCoder\AmoCRM_Wrap\Helpers
14
 */
15
class Value
16
{
17
    /**
18
     * Адрес. Первая строка
19
     */
20
    const SUBTYPE_ADDRESS_LINE_1 = 1;
21
22
    /**
23
     * Адрес. Вторая строка
24
     */
25
    const SUBTYPE_ADDRESS_LINE_2 = 2;
26
27
    /**
28
     * Город
29
     */
30
    const SUBTYPE_CITY = 3;
31
32
    /**
33
     * Регион
34
     */
35
    const SUBTYPE_STATE = 4;
36
37
    /**
38
     * Индекс
39
     */
40
    const SUBTYPE_ZIP = 5;
41
42
    /**
43
     * Страна. Задается кодом (Например: RU, UA, KZ, и т.д.)
44
     */
45
    const SUBTYPE_COUNTRY = 6;
46
47
    /**
48
     * @var string
49
     */
50
    private $value;
51
52
    /**
53
     * @var string|null
54
     */
55
    private $enum;
56
57
    /**
58
     * @var int|null
59
     */
60
    private $subtype;
61
62
    /**
63
     * Value constructor.
64
     *
65
     * @param string      $value
66
     * @param string|null $enum
67
     * @param int|null    $subtype
68
     */
69
    public function __construct($value, $enum = null, $subtype = null)
70
    {
71
        $this->value = $value;
72
        $this->enum = (int)$enum;
73
        $this->subtype = $subtype;
74
    }
75
76
    /**
77
     * @param $data
78
     *
79
     * @return Value
80
     */
81
    public static function loadInRaw($data)
82
    {
83
        if (!isset($data->enum)) {
84
            $data->enum = null;
85
        }
86
        if (!isset($data->subtype)) {
87
            $data->subtype = null;
88
        }
89
        return new Value($data->value, $data->enum, $data->subtype);
90
    }
91
92
    /**
93
     * @param string $value
94
     *
95
     * @return Value
96
     */
97
    public function setValue($value)
98
    {
99
        $this->value = $value;
100
        return $this;
101
    }
102
103
    /**
104
     * @return string
105
     */
106
    public function getValue()
107
    {
108
        return $this->value;
109
    }
110
111
    /**
112
     * @param string $enum
113
     *
114
     * @return Value
115
     */
116
    public function setEnum($enum)
117
    {
118
        $this->enum = $enum;
119
120
        return $this;
121
    }
122
123
    /**
124
     * @return null|string
125
     */
126
    public function getEnum()
127
    {
128
        return $this->enum;
129
    }
130
131
    /**
132
     * @return int|null
133
     */
134
    public function getSubtype()
135
    {
136
        return $this->subtype;
137
    }
138
}