1 | <?php |
||
2 | |||
3 | namespace libphonenumber; |
||
4 | |||
5 | /** |
||
6 | * Phone Number Description |
||
7 | */ |
||
8 | class PhoneNumberDesc |
||
9 | { |
||
10 | protected $hasNationalNumberPattern = false; |
||
11 | protected $nationalNumberPattern = ''; |
||
12 | protected $hasExampleNumber = false; |
||
13 | protected $exampleNumber = ''; |
||
14 | /** |
||
15 | * @var array |
||
16 | */ |
||
17 | protected $possibleLength; |
||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $possibleLengthLocalOnly; |
||
22 | |||
23 | 1614 | public function __construct() |
|
24 | { |
||
25 | 1614 | $this->clear(); |
|
26 | 1614 | } |
|
27 | |||
28 | /** |
||
29 | * @return PhoneNumberDesc |
||
30 | */ |
||
31 | 1614 | public function clear() |
|
32 | { |
||
33 | 1614 | $this->clearNationalNumberPattern(); |
|
34 | 1614 | $this->clearPossibleLength(); |
|
35 | 1614 | $this->clearPossibleLengthLocalOnly(); |
|
36 | 1614 | $this->clearExampleNumber(); |
|
37 | |||
38 | 1614 | return $this; |
|
39 | } |
||
40 | |||
41 | /** |
||
42 | * @return array |
||
43 | */ |
||
44 | 3860 | public function getPossibleLength() |
|
45 | { |
||
46 | 3860 | return $this->possibleLength; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param array $possibleLength |
||
51 | */ |
||
52 | 1604 | public function setPossibleLength($possibleLength) |
|
53 | { |
||
54 | 1604 | $this->possibleLength = $possibleLength; |
|
55 | 1604 | } |
|
56 | |||
57 | 11 | public function addPossibleLength($possibleLength) |
|
58 | { |
||
59 | 11 | if (!in_array($possibleLength, $this->possibleLength)) { |
|
60 | 11 | $this->possibleLength[] = $possibleLength; |
|
61 | } |
||
62 | 11 | } |
|
63 | |||
64 | 1614 | public function clearPossibleLength() |
|
65 | { |
||
66 | 1614 | $this->possibleLength = array(); |
|
67 | 1614 | } |
|
68 | |||
69 | /** |
||
70 | * @return array |
||
71 | */ |
||
72 | 3808 | public function getPossibleLengthLocalOnly() |
|
73 | { |
||
74 | 3808 | return $this->possibleLengthLocalOnly; |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * @param array $possibleLengthLocalOnly |
||
79 | */ |
||
80 | 1589 | public function setPossibleLengthLocalOnly($possibleLengthLocalOnly) |
|
81 | { |
||
82 | 1589 | $this->possibleLengthLocalOnly = $possibleLengthLocalOnly; |
|
83 | 1589 | } |
|
84 | |||
85 | 9 | public function addPossibleLengthLocalOnly($possibleLengthLocalOnly) |
|
86 | { |
||
87 | 9 | if (!in_array($possibleLengthLocalOnly, $this->possibleLengthLocalOnly)) { |
|
88 | 9 | $this->possibleLengthLocalOnly[] = $possibleLengthLocalOnly; |
|
89 | } |
||
90 | 9 | } |
|
91 | |||
92 | 1614 | public function clearPossibleLengthLocalOnly() |
|
93 | { |
||
94 | 1614 | $this->possibleLengthLocalOnly = array(); |
|
95 | 1614 | } |
|
96 | |||
97 | /** |
||
98 | * @return boolean |
||
99 | */ |
||
100 | 497 | public function hasNationalNumberPattern() |
|
101 | { |
||
102 | 497 | return $this->hasNationalNumberPattern; |
|
103 | } |
||
104 | |||
105 | /** |
||
106 | * @return string |
||
107 | */ |
||
108 | 3424 | public function getNationalNumberPattern() |
|
109 | { |
||
110 | 3424 | return $this->nationalNumberPattern; |
|
111 | } |
||
112 | |||
113 | /** |
||
114 | * @param string $value |
||
115 | * @return PhoneNumberDesc |
||
116 | */ |
||
117 | 1595 | public function setNationalNumberPattern($value) |
|
118 | { |
||
119 | 1595 | $this->hasNationalNumberPattern = true; |
|
120 | 1595 | $this->nationalNumberPattern = $value; |
|
121 | |||
122 | 1595 | return $this; |
|
123 | } |
||
124 | |||
125 | /** |
||
126 | * @return PhoneNumberDesc |
||
127 | */ |
||
128 | 1614 | public function clearNationalNumberPattern() |
|
129 | { |
||
130 | 1614 | $this->hasNationalNumberPattern = false; |
|
131 | 1614 | $this->nationalNumberPattern = ''; |
|
132 | 1614 | return $this; |
|
133 | } |
||
134 | |||
135 | /** |
||
136 | * @return string |
||
137 | */ |
||
138 | 5626 | public function hasExampleNumber() |
|
139 | { |
||
140 | 5626 | return $this->hasExampleNumber; |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
141 | } |
||
142 | |||
143 | /** |
||
144 | * @return string |
||
145 | */ |
||
146 | 3564 | public function getExampleNumber() |
|
147 | { |
||
148 | 3564 | return $this->exampleNumber; |
|
149 | } |
||
150 | |||
151 | /** |
||
152 | * @param string $value |
||
153 | * @return PhoneNumberDesc |
||
154 | */ |
||
155 | 1589 | public function setExampleNumber($value) |
|
156 | { |
||
157 | 1589 | $this->hasExampleNumber = true; |
|
158 | 1589 | $this->exampleNumber = $value; |
|
159 | |||
160 | 1589 | return $this; |
|
161 | } |
||
162 | |||
163 | /** |
||
164 | * @return PhoneNumberDesc |
||
165 | */ |
||
166 | 1614 | public function clearExampleNumber() |
|
167 | { |
||
168 | 1614 | $this->hasExampleNumber = false; |
|
169 | 1614 | $this->exampleNumber = ''; |
|
170 | |||
171 | 1614 | return $this; |
|
172 | } |
||
173 | |||
174 | /** |
||
175 | * @param PhoneNumberDesc $other |
||
176 | * @return PhoneNumberDesc |
||
177 | */ |
||
178 | 6 | public function mergeFrom(PhoneNumberDesc $other) |
|
179 | { |
||
180 | 6 | if ($other->hasNationalNumberPattern()) { |
|
181 | 6 | $this->setNationalNumberPattern($other->getNationalNumberPattern()); |
|
182 | } |
||
183 | 6 | if ($other->hasExampleNumber()) { |
|
184 | 6 | $this->setExampleNumber($other->getExampleNumber()); |
|
185 | } |
||
186 | 6 | $this->setPossibleLength($other->getPossibleLength()); |
|
187 | 6 | $this->setPossibleLengthLocalOnly($other->getPossibleLengthLocalOnly()); |
|
188 | |||
189 | 6 | return $this; |
|
190 | } |
||
191 | |||
192 | /** |
||
193 | * @param PhoneNumberDesc $other |
||
194 | * @return boolean |
||
195 | */ |
||
196 | public function exactlySameAs(PhoneNumberDesc $other) |
||
197 | { |
||
198 | return $this->nationalNumberPattern === $other->nationalNumberPattern && |
||
199 | $this->exampleNumber === $other->exampleNumber; |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * @return array |
||
204 | */ |
||
205 | 486 | public function toArray() |
|
206 | { |
||
207 | 486 | $data = array(); |
|
208 | 486 | if ($this->hasNationalNumberPattern()) { |
|
209 | 486 | $data['NationalNumberPattern'] = $this->getNationalNumberPattern(); |
|
210 | } |
||
211 | 486 | if ($this->hasExampleNumber()) { |
|
212 | 486 | $data['ExampleNumber'] = $this->getExampleNumber(); |
|
213 | } |
||
214 | |||
215 | 486 | $data['PossibleLength'] = $this->getPossibleLength(); |
|
216 | 486 | $data['PossibleLengthLocalOnly'] = $this->getPossibleLengthLocalOnly(); |
|
217 | |||
218 | 486 | return $data; |
|
219 | } |
||
220 | |||
221 | /** |
||
222 | * @param array $input |
||
223 | * @return PhoneNumberDesc |
||
224 | */ |
||
225 | 1582 | public function fromArray(array $input) |
|
226 | { |
||
227 | 1582 | if (isset($input['NationalNumberPattern']) && $input['NationalNumberPattern'] != '') { |
|
228 | 1582 | $this->setNationalNumberPattern($input['NationalNumberPattern']); |
|
229 | } |
||
230 | 1582 | if (isset($input['ExampleNumber']) && $input['NationalNumberPattern'] != '') { |
|
231 | 1582 | $this->setExampleNumber($input['ExampleNumber']); |
|
232 | } |
||
233 | 1582 | $this->setPossibleLength($input['PossibleLength']); |
|
234 | 1582 | $this->setPossibleLengthLocalOnly($input['PossibleLengthLocalOnly']); |
|
235 | |||
236 | 1582 | return $this; |
|
237 | } |
||
238 | } |
||
239 |