Completed
Push — master ( 54c69f...d7a840 )
by Joshua
10:29
created

PhoneNumberDesc   A

Complexity

Total Complexity 33

Size/Duplication

Total Lines 231
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 33
lcom 1
cbo 0
dl 0
loc 231
ccs 75
cts 80
cp 0.9375
rs 9.3999
c 0
b 0
f 0

22 Methods

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