Completed
Push — master ( dd9cf2...939550 )
by Joshua
13s
created

PhoneNumberDesc   A

Complexity

Total Complexity 33

Size/Duplication

Total Lines 231
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 96.47%

Importance

Changes 0
Metric Value
wmc 33
lcom 1
cbo 0
dl 0
loc 231
ccs 82
cts 85
cp 0.9647
rs 9.3999
c 0
b 0
f 0

22 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A clear() 0 9 1
A getPossibleLength() 0 4 1
A setPossibleLength() 0 4 1
A addPossibleLength() 0 6 2
A clearPossibleLength() 0 4 1
A getPossibleLengthLocalOnly() 0 4 1
A setPossibleLengthLocalOnly() 0 4 1
A addPossibleLengthLocalOnly() 0 6 2
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 setExampleNumber() 0 7 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 1602
    public function __construct()
24
    {
25 1602
        $this->clear();
26 1602
    }
27
28
    /**
29
     * @return PhoneNumberDesc
30
     */
31 1602
    public function clear()
32
    {
33 1602
        $this->clearNationalNumberPattern();
34 1602
        $this->clearPossibleLength();
35 1602
        $this->clearPossibleLengthLocalOnly();
36 1602
        $this->clearExampleNumber();
37
38 1602
        return $this;
39
    }
40
41
    /**
42
     * @return array
43
     */
44 3614
    public function getPossibleLength()
45
    {
46 3614
        return $this->possibleLength;
47
    }
48
49
    /**
50
     * @param array $possibleLength
51
     */
52 1592
    public function setPossibleLength($possibleLength)
53
    {
54 1592
        $this->possibleLength = $possibleLength;
55 1592
    }
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 1602
    public function clearPossibleLength()
65
    {
66 1602
        $this->possibleLength = array();
67 1602
    }
68
69
    /**
70
     * @return array
71
     */
72 3562
    public function getPossibleLengthLocalOnly()
73
    {
74 3562
        return $this->possibleLengthLocalOnly;
75
    }
76
77
    /**
78
     * @param array $possibleLengthLocalOnly
79
     */
80 1577
    public function setPossibleLengthLocalOnly($possibleLengthLocalOnly)
81
    {
82 1577
        $this->possibleLengthLocalOnly = $possibleLengthLocalOnly;
83 1577
    }
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 1602
    public function clearPossibleLengthLocalOnly()
93
    {
94 1602
        $this->possibleLengthLocalOnly = array();
95 1602
    }
96
97
    /**
98
     * @return boolean
99
     */
100 494
    public function hasNationalNumberPattern()
101
    {
102 494
        return $this->hasNationalNumberPattern;
103
    }
104
105
    /**
106
     * @return string
107
     */
108 3185
    public function getNationalNumberPattern()
109
    {
110 3185
        return $this->nationalNumberPattern;
111
    }
112
113
    /**
114
     * @param string $value
115
     * @return PhoneNumberDesc
116
     */
117 1583
    public function setNationalNumberPattern($value)
118
    {
119 1583
        $this->hasNationalNumberPattern = true;
120 1583
        $this->nationalNumberPattern = $value;
121
122 1583
        return $this;
123
    }
124
125
    /**
126
     * @return PhoneNumberDesc
127
     */
128 1602
    public function clearNationalNumberPattern()
129
    {
130 1602
        $this->hasNationalNumberPattern = false;
131 1602
        $this->nationalNumberPattern = '';
132 1602
        return $this;
133
    }
134
135
    /**
136
     * @return string
137
     */
138 5597
    public function hasExampleNumber()
139
    {
140 5597
        return $this->hasExampleNumber;
141
    }
142
143
    /**
144
     * @return string
145
     */
146 3326
    public function getExampleNumber()
147
    {
148 3326
        return $this->exampleNumber;
149
    }
150
151
    /**
152
     * @param string $value
153
     * @return PhoneNumberDesc
154
     */
155 1577
    public function setExampleNumber($value)
156
    {
157 1577
        $this->hasExampleNumber = true;
158 1577
        $this->exampleNumber = $value;
159
160 1577
        return $this;
161
    }
162
163
    /**
164
     * @return PhoneNumberDesc
165
     */
166 1602
    public function clearExampleNumber()
167
    {
168 1602
        $this->hasExampleNumber = false;
169 1602
        $this->exampleNumber = '';
170
171 1602
        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 483
    public function toArray()
206
    {
207 483
        $data = array();
208 483
        if ($this->hasNationalNumberPattern()) {
209 483
            $data['NationalNumberPattern'] = $this->getNationalNumberPattern();
210
        }
211 483
        if ($this->hasExampleNumber()) {
212 483
            $data['ExampleNumber'] = $this->getExampleNumber();
213
        }
214
215 483
        $data['PossibleLength'] = $this->getPossibleLength();
216 483
        $data['PossibleLengthLocalOnly'] = $this->getPossibleLengthLocalOnly();
217
218 483
        return $data;
219
    }
220
221
    /**
222
     * @param array $input
223
     * @return PhoneNumberDesc
224
     */
225 1570
    public function fromArray(array $input)
226
    {
227 1570
        if (isset($input['NationalNumberPattern']) && $input['NationalNumberPattern'] != '') {
228 1570
            $this->setNationalNumberPattern($input['NationalNumberPattern']);
229
        }
230 1570
        if (isset($input['ExampleNumber']) && $input['NationalNumberPattern'] != '') {
231 1570
            $this->setExampleNumber($input['ExampleNumber']);
232
        }
233 1570
        $this->setPossibleLength($input['PossibleLength']);
234 1570
        $this->setPossibleLengthLocalOnly($input['PossibleLengthLocalOnly']);
235
236 1570
        return $this;
237
    }
238
}
239