Completed
Pull Request — master (#131)
by
unknown
15:54
created

PhoneNumberDesc   A

Complexity

Total Complexity 33

Size/Duplication

Total Lines 227
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 78.56%

Importance

Changes 0
Metric Value
wmc 33
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 227
rs 9.3999
ccs 44
cts 56
cp 0.7856

19 Methods

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