Completed
Push — upstream-8.4.3 ( a81bcc )
by Joshua
17:43
created

getNationalPrefixOptionalWhenFormatting()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace libphonenumber;
4
5
/**
6
 * Number Format
7
 */
8
class NumberFormat
9
{
10
    protected $pattern = null;
11
    protected $format = null;
12
    protected $leadingDigitsPattern = array();
13
    protected $nationalPrefixFormattingRule = null;
14
    /**
15
     * @var bool
16
     */
17
    protected $nationalPrefixOptionalWhenFormatting = false;
18
    protected $domesticCarrierCodeFormattingRule = null;
19
20
    public function __construct()
21
    {
22
        $this->clear();
23
    }
24
25
    /**
26
     * @return NumberFormat
27
     */
28
    public function clear()
29
    {
30
        $this->pattern = "";
31
        $this->format = "";
32
        $this->leadingDigitsPattern = array();
33
        $this->nationalPrefixFormattingRule = "";
34
        $this->nationalPrefixOptionalWhenFormatting = false;
35
        $this->domesticCarrierCodeFormattingRule = "";
36
37
        return $this;
38
    }
39
40
    /**
41
     * @return boolean
42
     */
43
    public function hasPattern()
44
    {
45
        return isset($this->pattern);
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getPattern()
52
    {
53
        return $this->pattern;
54
    }
55
56
    /**
57
     * @param string $value
58
     * @return NumberFormat
59
     */
60
    public function setPattern($value)
61
    {
62
        $this->pattern = $value;
63
64
        return $this;
65
    }
66
67
    /**
68
     * @return boolean
69
     */
70
    public function hasNationalPrefixOptionalWhenFormatting()
71
    {
72
        return isset($this->nationalPrefixOptionalWhenFormatting);
73
    }
74
75
    /**
76
     * @return boolean
77
     */
78
    public function getNationalPrefixOptionalWhenFormatting()
79
    {
80
        return $this->nationalPrefixOptionalWhenFormatting;
81
    }
82
83
    /**
84
     * @param boolean $nationalPrefixOptionalWhenFormatting
85
     */
86
    public function setNationalPrefixOptionalWhenFormatting($nationalPrefixOptionalWhenFormatting)
87
    {
88
        $this->nationalPrefixOptionalWhenFormatting = $nationalPrefixOptionalWhenFormatting;
89
    }
90
91
    /**
92
     * @return boolean
93
     */
94
    public function hasFormat()
95
    {
96
        return ($this->format);
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public function getFormat()
103
    {
104
        return $this->format;
105
    }
106
107
    /**
108
     * @param string $value
109
     * @return NumberFormat
110
     */
111
    public function setFormat($value)
112
    {
113
        $this->format = $value;
114
115
        return $this;
116
    }
117
118
    /**
119
     * @return string
120
     */
121
    public function leadingDigitPatterns()
122
    {
123
        return $this->leadingDigitsPattern;
124
    }
125
126
    /**
127
     * @return int
128
     */
129
    public function leadingDigitsPatternSize()
130
    {
131
        return count($this->leadingDigitsPattern);
132
    }
133
134
    /**
135
     * @param int $index
136
     * @return string
137
     */
138
    public function getLeadingDigitsPattern($index)
139
    {
140
        return $this->leadingDigitsPattern[$index];
141
    }
142
143
    /**
144
     * @param string $value
145
     * @return NumberFormat
146
     */
147
    public function addLeadingDigitsPattern($value)
148
    {
149
        $this->leadingDigitsPattern[] = $value;
150
151
        return $this;
152
    }
153
154
    /**
155
     * @return boolean
156
     */
157
    public function hasNationalPrefixFormattingRule()
158
    {
159
        return isset($this->nationalPrefixFormattingRule);
160
    }
161
162
    /**
163
     * @return string
164
     */
165
    public function getNationalPrefixFormattingRule()
166
    {
167
        return $this->nationalPrefixFormattingRule;
168
    }
169
170
    /**
171
     * @param string $value
172
     * @return NumberFormat
173
     */
174
    public function setNationalPrefixFormattingRule($value)
175
    {
176
        $this->nationalPrefixFormattingRule = $value;
177
178
        return $this;
179
    }
180
181
    /**
182
     * @return NumberFormat
183
     */
184
    public function clearNationalPrefixFormattingRule()
185
    {
186
        $this->nationalPrefixFormattingRule = null;
187
188
        return $this;
189
    }
190
191
    /**
192
     * @return boolean
193
     */
194
    public function hasDomesticCarrierCodeFormattingRule()
195
    {
196
        return isset($this->domesticCarrierCodeFormattingRule);
197
    }
198
199
    /**
200
     * @return string
201
     */
202
    public function getDomesticCarrierCodeFormattingRule()
203
    {
204
        return $this->domesticCarrierCodeFormattingRule;
205
    }
206
207
    /**
208
     * @param string $value
209
     * @return NumberFormat
210
     */
211
    public function setDomesticCarrierCodeFormattingRule($value)
212
    {
213
        $this->domesticCarrierCodeFormattingRule = $value;
214
215
        return $this;
216
    }
217
218
    /**
219
     * @param NumberFormat $other
220
     * @return NumberFormat
221
     */
222
    public function mergeFrom(NumberFormat $other)
223
    {
224
        if ($other->hasPattern()) {
225
            $this->setPattern($other->getPattern());
226
        }
227
        if ($other->hasFormat()) {
228
            $this->setFormat($other->getFormat());
229
        }
230
        $leadingDigitsPatternSize = $other->leadingDigitsPatternSize();
231
        for ($i = 0; $i < $leadingDigitsPatternSize; $i++) {
232
            $this->addLeadingDigitsPattern($other->getLeadingDigitsPattern($i));
233
        }
234
        if ($other->hasNationalPrefixFormattingRule()) {
235
            $this->setNationalPrefixFormattingRule($other->getNationalPrefixFormattingRule());
236
        }
237
        if ($other->hasDomesticCarrierCodeFormattingRule()) {
238
            $this->setDomesticCarrierCodeFormattingRule($other->getDomesticCarrierCodeFormattingRule());
239
        }
240
        if ($other->hasNationalPrefixOptionalWhenFormatting()) {
241
            $this->setNationalPrefixOptionalWhenFormatting($other->getNationalPrefixOptionalWhenFormatting());
242
        }
243
244
        return $this;
245
    }
246
247
    /**
248
     * @return array
249
     */
250
    public function toArray()
251
    {
252
        $output = array();
253
        $output['pattern'] = $this->getPattern();
254
        $output['format'] = $this->getFormat();
255
256
        $output['leadingDigitsPatterns'] = $this->leadingDigitPatterns();
257
258
        if ($this->hasNationalPrefixFormattingRule()) {
259
            $output['nationalPrefixFormattingRule'] = $this->getNationalPrefixFormattingRule();
260
        }
261
262
        if ($this->hasDomesticCarrierCodeFormattingRule()) {
263
            $output['domesticCarrierCodeFormattingRule'] = $this->getDomesticCarrierCodeFormattingRule();
264
        }
265
266
        if ($this->hasNationalPrefixOptionalWhenFormatting()) {
267
            $output['nationalPrefixOptionalWhenFormatting'] = $this->getNationalPrefixOptionalWhenFormatting();
268
        }
269
270
        return $output;
271
    }
272
273
    /**
274
     * @param array $input
275
     */
276
    public function fromArray(array $input)
277
    {
278
        $this->setPattern($input['pattern']);
279
        $this->setFormat($input['format']);
280
        foreach ($input['leadingDigitsPatterns'] as $leadingDigitsPattern) {
281
            $this->addLeadingDigitsPattern($leadingDigitsPattern);
282
        }
283
284
        if (isset($input['nationalPrefixFormattingRule'])) {
285
            $this->setNationalPrefixFormattingRule($input['nationalPrefixFormattingRule']);
286
        }
287
        if (isset($input['domesticCarrierCodeFormattingRule'])) {
288
            $this->setDomesticCarrierCodeFormattingRule($input['domesticCarrierCodeFormattingRule']);
289
        }
290
291
        if (isset($input['nationalPrefixOptionalWhenFormatting'])) {
292
            $this->setNationalPrefixOptionalWhenFormatting($input['nationalPrefixOptionalWhenFormatting']);
293
        }
294
    }
295
}
296