Completed
Push — reducePrefixMapperFileCount ( 09d7d0...7b6d76 )
by Joshua
20:39 queued 08:53
created

PhoneNumberDesc   B

Complexity

Total Complexity 39

Size/Duplication

Total Lines 251
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 83.65%

Importance

Changes 0
Metric Value
wmc 39
lcom 1
cbo 0
dl 0
loc 251
ccs 87
cts 104
cp 0.8365
rs 8.2857
c 0
b 0
f 0

23 Methods

Rating   Name   Duplication   Size   Complexity  
A clear() 0 10 1
A getPossibleLength() 0 4 1
A setPossibleLength() 0 4 1
A __construct() 0 4 1
A clearPossibleLength() 0 4 1
A getPossibleLengthLocalOnly() 0 4 1
A setPossibleLengthLocalOnly() 0 4 1
A clearPossibleLengthLocalOnly() 0 4 1
A getNationalNumberPattern() 0 4 1
A setNationalNumberPattern() 0 7 1
A getPossibleNumberPattern() 0 4 1
A setPossibleNumberPattern() 0 7 1
A hasExampleNumber() 0 4 1
A getExampleNumber() 0 4 1
A setExampleNumber() 0 7 1
A addPossibleLength() 0 6 2
A addPossibleLengthLocalOnly() 0 6 2
A mergeFrom() 0 16 4
A exactlySameAs() 0 6 3
B fromArray() 0 16 7
A hasNationalNumberPattern() 0 4 1
A hasPossibleNumberPattern() 0 4 1
A toArray() 0 18 4
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 $hasPossibleNumberPattern = false;
13
    protected $possibleNumberPattern = "";
14
    protected $hasExampleNumber = false;
15
    protected $exampleNumber = "";
16
    /**
17
     * @var array
18
     */
19
    protected $possibleLength;
20
    /**
21
     * @var array
22
     */
23
    protected $possibleLengthLocalOnly;
24
25 1375
    public function __construct()
26
    {
27 1375
        $this->clear();
28 1375
    }
29
30
    /**
31
     * @return PhoneNumberDesc
32
     */
33 1375
    public function clear()
34
    {
35 1375
        $this->nationalNumberPattern = "";
36 1375
        $this->possibleNumberPattern = "";
37 1375
        $this->clearPossibleLength();
38 1375
        $this->clearPossibleLengthLocalOnly();
39 1375
        $this->exampleNumber = "";
40
41 1375
        return $this;
42
    }
43
44
    /**
45
     * @return array
46
     */
47 3274
    public function getPossibleLength()
48
    {
49 3274
        return $this->possibleLength;
50
    }
51
52
    /**
53
     * @param array $possibleLength
54
     */
55 1363
    public function setPossibleLength($possibleLength)
56
    {
57 1363
        $this->possibleLength = $possibleLength;
58 1363
    }
59
60 5
    public function addPossibleLength($possibleLength)
61
    {
62 5
        if (!in_array($possibleLength, $this->possibleLength)) {
63 5
            $this->possibleLength[] = $possibleLength;
64 5
        }
65 5
    }
66
67 1375
    public function clearPossibleLength()
68
    {
69 1375
        $this->possibleLength = array();
70 1375
    }
71
72
    /**
73
     * @return array
74
     */
75 3224
    public function getPossibleLengthLocalOnly()
76
    {
77 3224
        return $this->possibleLengthLocalOnly;
78
    }
79
80
    /**
81
     * @param array $possibleLengthLocalOnly
82
     */
83 1349
    public function setPossibleLengthLocalOnly($possibleLengthLocalOnly)
84
    {
85 1349
        $this->possibleLengthLocalOnly = $possibleLengthLocalOnly;
86 1349
    }
87
88 1
    public function addPossibleLengthLocalOnly($possibleLengthLocalOnly)
89
    {
90 1
        if (!in_array($possibleLengthLocalOnly, $this->possibleLengthLocalOnly)) {
91 1
            $this->possibleLengthLocalOnly[] = $possibleLengthLocalOnly;
92 1
        }
93 1
    }
94
95 1375
    public function clearPossibleLengthLocalOnly()
96
    {
97 1375
        $this->possibleLengthLocalOnly = array();
98 1375
    }
99
100
    /**
101
     * @return boolean
102
     */
103 482
    public function hasNationalNumberPattern()
104
    {
105 482
        return $this->hasNationalNumberPattern;
106
    }
107
108
    /**
109
     * @return string
110
     */
111 2924
    public function getNationalNumberPattern()
112
    {
113 2924
        return $this->nationalNumberPattern;
114
    }
115
116
    /**
117
     * @param string $value
118
     * @return PhoneNumberDesc
119
     */
120 1353
    public function setNationalNumberPattern($value)
121
    {
122 1353
        $this->hasNationalNumberPattern = true;
123 1353
        $this->nationalNumberPattern = $value;
124
125 1353
        return $this;
126
    }
127
128
    /**
129
     * @return boolean
130
     */
131 482
    public function hasPossibleNumberPattern()
132
    {
133 482
        return $this->hasPossibleNumberPattern;
134
    }
135
136
    /**
137
     * @return string
138
     */
139 1094
    public function getPossibleNumberPattern()
140
    {
141 1094
        return $this->possibleNumberPattern;
142
    }
143
144
    /**
145
     * @param string $value
146
     * @return PhoneNumberDesc
147
     */
148 1355
    public function setPossibleNumberPattern($value)
149
    {
150 1355
        $this->hasPossibleNumberPattern = true;
151 1355
        $this->possibleNumberPattern = $value;
152
153 1355
        return $this;
154
    }
155
156
    /**
157
     * @return string
158
     */
159 5346
    public function hasExampleNumber()
160
    {
161 5346
        return $this->hasExampleNumber;
162
    }
163
164
    /**
165
     * @return string
166
     */
167 3177
    public function getExampleNumber()
168
    {
169 3177
        return $this->exampleNumber;
170
    }
171
172
    /**
173
     * @param string $value
174
     * @return PhoneNumberDesc
175
     */
176 1331
    public function setExampleNumber($value)
177
    {
178 1331
        $this->hasExampleNumber = true;
179 1331
        $this->exampleNumber = $value;
180
181 1331
        return $this;
182
    }
183
184
    /**
185
     * @param PhoneNumberDesc $other
186
     * @return PhoneNumberDesc
187
     */
188
    public function mergeFrom(PhoneNumberDesc $other)
189
    {
190
        if ($other->hasNationalNumberPattern()) {
191
            $this->setNationalNumberPattern($other->getNationalNumberPattern());
192
        }
193
        if ($other->hasPossibleNumberPattern()) {
194
            $this->setPossibleNumberPattern($other->getPossibleNumberPattern());
195
        }
196
        if ($other->hasExampleNumber()) {
197
            $this->setExampleNumber($other->getExampleNumber());
198
        }
199
        $this->setPossibleLength($other->getPossibleLength());
200
        $this->setPossibleLengthLocalOnly($other->getPossibleLengthLocalOnly());
201
202
        return $this;
203
    }
204
205
    /**
206
     * @param PhoneNumberDesc $other
207
     * @return boolean
208
     */
209
    public function exactlySameAs(PhoneNumberDesc $other)
210
    {
211
        return $this->nationalNumberPattern === $other->nationalNumberPattern &&
212
        $this->possibleNumberPattern === $other->possibleNumberPattern &&
213
        $this->exampleNumber === $other->exampleNumber;
214
    }
215
216
    /**
217
     * @return array
218
     */
219 482
    public function toArray()
220
    {
221 482
        $data = array();
222 482
        if ($this->hasNationalNumberPattern()) {
223 482
            $data['NationalNumberPattern'] = $this->getNationalNumberPattern();
224 482
        }
225 482
        if ($this->hasPossibleNumberPattern()) {
226 482
            $data['PossibleNumberPattern'] = $this->getPossibleNumberPattern();
227 482
        }
228 482
        if ($this->hasExampleNumber()) {
229 482
            $data['ExampleNumber'] = $this->getExampleNumber();
230 482
        }
231
232 482
        $data['PossibleLength'] = $this->getPossibleLength();
233 482
        $data['PossibleLengthLocalOnly'] = $this->getPossibleLengthLocalOnly();
234
235 482
        return $data;
236
    }
237
238
    /**
239
     * @param array $input
240
     * @return PhoneNumberDesc
241
     */
242 1348
    public function fromArray(array $input)
243
    {
244 1348
        if (isset($input['NationalNumberPattern']) && $input['NationalNumberPattern'] != '') {
245 1348
            $this->setNationalNumberPattern($input['NationalNumberPattern']);
246 1348
        }
247 1348
        if (isset($input['PossibleNumberPattern']) && $input['NationalNumberPattern'] != '') {
248 1348
            $this->setPossibleNumberPattern($input['PossibleNumberPattern']);
249 1348
        }
250 1348
        if (isset($input['ExampleNumber']) && $input['NationalNumberPattern'] != '') {
251 1330
            $this->setExampleNumber($input['ExampleNumber']);
252 1330
        }
253 1348
        $this->setPossibleLength($input['PossibleLength']);
254 1348
        $this->setPossibleLengthLocalOnly($input['PossibleLengthLocalOnly']);
255
256 1348
        return $this;
257
    }
258
}
259