Passed
Push — upstream-8.9.2 ( 6a22e8 )
by Joshua
25:34 queued 09:29
created

LocaleTest::getCountryCodes()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 238
Code Lines 235

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 238
rs 8.2857
c 0
b 0
f 0
cc 1
eloc 235
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 *
4
 *
5
 * @author joshuag
6
 * @created: 14/08/2014 12:35
7
 * @project libphonenumber-for-php
8
 */
9
10
namespace libphonenumber\Tests\Issues;
11
12
use libphonenumber\CountryCodeToRegionCodeMap;
13
use libphonenumber\geocoding\PhoneNumberOfflineGeocoder;
14
use libphonenumber\PhoneNumberType;
15
use libphonenumber\PhoneNumberUtil;
16
17
class LocaleTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * @var PhoneNumberOfflineGeocoder
21
     */
22
    private $geocoder;
23
24
    /**
25
     * @var PhoneNumberUtil
26
     */
27
    private $phoneUtil;
28
29
    public function setUp()
30
    {
31
        PhoneNumberUtil::resetInstance();
32
        PhoneNumberOfflineGeocoder::resetInstance();
33
        $this->phoneUtil = PhoneNumberUtil::getInstance();
34
        $this->geocoder = PhoneNumberOfflineGeocoder::getInstance();
35
    }
36
37
    /**
38
     * @dataProvider localeList
39
     * @param string $regionCode
40
     * @param string $countryName
41
     */
42
    public function testLocales($regionCode, $countryName)
43
    {
44
        if (!in_array($regionCode, $this->phoneUtil->getSupportedRegions())) {
45
            $this->markTestSkipped("{$regionCode} is not supported");
46
        }
47
48
        $phoneNumber = $this->phoneUtil->getExampleNumberForType($regionCode, PhoneNumberType::FIXED_LINE_OR_MOBILE);
49
50
        $this->assertContains($regionCode, CountryCodeToRegionCodeMap::$countryCodeToRegionCodeMap[$phoneNumber->getCountryCode()]);
51
52
        $this->assertEquals($regionCode, $this->phoneUtil->getRegionCodeForNumber($phoneNumber));
53
54
        $this->assertEquals($countryName, $this->geocoder->getDescriptionForValidNumber($phoneNumber, 'en', 'ZZ'), "Checking {$phoneNumber} is part of {$countryName}");
55
    }
56
57
    public function localeList()
58
    {
59
        $codes = $this->getCountryCodes();
60
61
        $return = array();
62
        foreach ($codes as $code => $country) {
63
            $return[] = array($code, $country);
64
        }
65
66
        return $return;
67
    }
68
69
    /**
70
     * This list was got from the Internet, and altered slightly to make the tests pass
71
     *
72
     * @see https://gist.github.com/vxnick/380904
73
     * @return array
74
     */
75
    private function getCountryCodes()
76
    {
77
        return array(
78
            'AF' => 'Afghanistan',
79
            'AX' => 'Åland Islands',
80
            'AL' => 'Albania',
81
            'DZ' => 'Algeria',
82
            'AS' => 'American Samoa',
83
            'AD' => 'Andorra',
84
            'AO' => 'Angola',
85
            'AI' => 'Anguilla',
86
            'AG' => 'Antigua & Barbuda',
87
            'AR' => 'Argentina',
88
            'AU' => 'Australia',
89
            'AT' => 'Austria',
90
            'AZ' => 'Azerbaijan',
91
            'BS' => 'Bahamas',
92
            'BH' => 'Bahrain',
93
            'BD' => 'Bangladesh',
94
            'BB' => 'Barbados',
95
            'BY' => 'Belarus',
96
            'BE' => 'Belgium',
97
            'BZ' => 'Belize',
98
            'BJ' => 'Benin',
99
            'BM' => 'Bermuda',
100
            'BT' => 'Bhutan',
101
            'BO' => 'Bolivia',
102
            'BA' => 'Bosnia & Herzegovina',
103
            'BW' => 'Botswana',
104
            'BR' => 'Brazil',
105
            'IO' => 'British Indian Ocean Territory',
106
            'BN' => 'Brunei',
107
            'BG' => 'Bulgaria',
108
            'BF' => 'Burkina Faso',
109
            'BI' => 'Burundi',
110
            'KH' => 'Cambodia',
111
            'CM' => 'Cameroon',
112
            'CA' => 'Canada',
113
            'CV' => 'Cape Verde',
114
            'KY' => 'Cayman Islands',
115
            'CF' => 'Central African Republic',
116
            'TD' => 'Chad',
117
            'CL' => 'Chile',
118
            'CN' => 'China',
119
            'CX' => 'Christmas Island',
120
            'CC' => 'Cocos (Keeling) Islands',
121
            'CO' => 'Colombia',
122
            'KM' => 'Comoros',
123
            'CG' => 'Congo - Brazzaville',
124
            'CD' => 'Congo - Kinshasa',
125
            'CK' => 'Cook Islands',
126
            'CR' => 'Costa Rica',
127
            'CI' => 'Côte d’Ivoire',
128
            'HR' => 'Croatia',
129
            'CU' => 'Cuba',
130
            'CY' => 'Cyprus',
131
            'CZ' => 'Czechia',
132
            'DK' => 'Denmark',
133
            'DJ' => 'Djibouti',
134
            'DM' => 'Dominica',
135
            'DO' => 'Dominican Republic',
136
            'EC' => 'Ecuador',
137
            'EG' => 'Egypt',
138
            'SV' => 'El Salvador',
139
            'GQ' => 'Equatorial Guinea',
140
            'ER' => 'Eritrea',
141
            'EE' => 'Estonia',
142
            'ET' => 'Ethiopia',
143
            'FK' => 'Falkland Islands',
144
            'FO' => 'Faroe Islands',
145
            'FJ' => 'Fiji',
146
            'FI' => 'Finland',
147
            'FR' => 'France',
148
            'GF' => 'French Guiana',
149
            'PF' => 'French Polynesia',
150
            'GA' => 'Gabon',
151
            'GM' => 'Gambia',
152
            'GE' => 'Georgia',
153
            'DE' => 'Germany',
154
            'GH' => 'Ghana',
155
            'GI' => 'Gibraltar',
156
            'GR' => 'Greece',
157
            'GL' => 'Greenland',
158
            'GD' => 'Grenada',
159
            'GP' => 'Guadeloupe',
160
            'GU' => 'Guam',
161
            'GT' => 'Guatemala',
162
            'GG' => 'Guernsey',
163
            'GN' => 'Guinea',
164
            'GW' => 'Guinea-Bissau',
165
            'GY' => 'Guyana',
166
            'HT' => 'Haiti',
167
            'HN' => 'Honduras',
168
            'HK' => 'Hong Kong SAR China',
169
            'HU' => 'Hungary',
170
            'IS' => 'Iceland',
171
            'IN' => 'India',
172
            'ID' => 'Indonesia',
173
            'IR' => 'Iran',
174
            'IQ' => 'Iraq',
175
            'IE' => 'Ireland',
176
            'IM' => 'Isle of Man',
177
            'IL' => 'Israel',
178
            'IT' => 'Italy',
179
            'JM' => 'Jamaica',
180
            'JP' => 'Japan',
181
            'JE' => 'Jersey',
182
            'JO' => 'Jordan',
183
            'KZ' => 'Kazakhstan',
184
            'KE' => 'Kenya',
185
            'KI' => 'Kiribati',
186
            'KP' => 'North Korea',
187
            'KR' => 'South Korea',
188
            'KW' => 'Kuwait',
189
            'KG' => 'Kyrgyzstan',
190
            'LA' => 'Laos',
191
            'LV' => 'Latvia',
192
            'LB' => 'Lebanon',
193
            'LS' => 'Lesotho',
194
            'LR' => 'Liberia',
195
            'LY' => 'Libya',
196
            'LI' => 'Liechtenstein',
197
            'LT' => 'Lithuania',
198
            'LU' => 'Luxembourg',
199
            'MO' => 'Macau SAR China',
200
            'MK' => 'Macedonia',
201
            'MG' => 'Madagascar',
202
            'MW' => 'Malawi',
203
            'MY' => 'Malaysia',
204
            'MV' => 'Maldives',
205
            'ML' => 'Mali',
206
            'MT' => 'Malta',
207
            'MH' => 'Marshall Islands',
208
            'MQ' => 'Martinique',
209
            'MR' => 'Mauritania',
210
            'MU' => 'Mauritius',
211
            'YT' => 'Mayotte',
212
            'MX' => 'Mexico',
213
            'FM' => 'Micronesia',
214
            'MD' => 'Moldova',
215
            'MC' => 'Monaco',
216
            'MN' => 'Mongolia',
217
            'ME' => 'Montenegro',
218
            'MS' => 'Montserrat',
219
            'MA' => 'Morocco',
220
            'MZ' => 'Mozambique',
221
            'MM' => 'Myanmar (Burma)',
222
            'NA' => 'Namibia',
223
            'NR' => 'Nauru',
224
            'NP' => 'Nepal',
225
            'NL' => 'Netherlands',
226
            'NC' => 'New Caledonia',
227
            'NZ' => 'New Zealand',
228
            'NI' => 'Nicaragua',
229
            'NE' => 'Niger',
230
            'NG' => 'Nigeria',
231
            'NU' => 'Niue',
232
            'NF' => 'Norfolk Island',
233
            'MP' => 'Northern Mariana Islands',
234
            'NO' => 'Norway',
235
            'OM' => 'Oman',
236
            'PK' => 'Pakistan',
237
            'PW' => 'Palau',
238
            'PS' => 'Palestinian Territories',
239
            'PA' => 'Panama',
240
            'PG' => 'Papua New Guinea',
241
            'PY' => 'Paraguay',
242
            'PE' => 'Peru',
243
            'PH' => 'Philippines',
244
            'PL' => 'Poland',
245
            'PT' => 'Portugal',
246
            'PR' => 'Puerto Rico',
247
            'QA' => 'Qatar',
248
            'RE' => 'Réunion',
249
            'RO' => 'Romania',
250
            'RU' => 'Russia',
251
            'RW' => 'Rwanda',
252
            'SH' => 'St. Helena',
253
            'KN' => 'St. Kitts & Nevis',
254
            'LC' => 'St. Lucia',
255
            'PM' => 'St. Pierre & Miquelon',
256
            'VC' => 'St. Vincent & Grenadines',
257
            'WS' => 'Samoa',
258
            'SM' => 'San Marino',
259
            'ST' => 'São Tomé & Príncipe',
260
            'SA' => 'Saudi Arabia',
261
            'SN' => 'Senegal',
262
            'RS' => 'Serbia',
263
            'SC' => 'Seychelles',
264
            'SL' => 'Sierra Leone',
265
            'SG' => 'Singapore',
266
            'SK' => 'Slovakia',
267
            'SI' => 'Slovenia',
268
            'SB' => 'Solomon Islands',
269
            'SO' => 'Somalia',
270
            'ZA' => 'South Africa',
271
            'ES' => 'Spain',
272
            'LK' => 'Sri Lanka',
273
            'SD' => 'Sudan',
274
            'SR' => 'Suriname',
275
            'SJ' => 'Svalbard & Jan Mayen',
276
            'SZ' => 'Swaziland',
277
            'SE' => 'Sweden',
278
            'CH' => 'Switzerland',
279
            'SY' => 'Syria',
280
            'TW' => 'Taiwan',
281
            'TJ' => 'Tajikistan',
282
            'TZ' => 'Tanzania',
283
            'TH' => 'Thailand',
284
            'TL' => 'Timor-Leste',
285
            'TG' => 'Togo',
286
            'TK' => 'Tokelau',
287
            'TO' => 'Tonga',
288
            'TT' => 'Trinidad & Tobago',
289
            'TN' => 'Tunisia',
290
            'TR' => 'Turkey',
291
            'TM' => 'Turkmenistan',
292
            'TC' => 'Turks & Caicos Islands',
293
            'TV' => 'Tuvalu',
294
            'UG' => 'Uganda',
295
            'UA' => 'Ukraine',
296
            'AE' => 'United Arab Emirates',
297
            'GB' => 'United Kingdom',
298
            'US' => 'United States',
299
            'UY' => 'Uruguay',
300
            'UZ' => 'Uzbekistan',
301
            'VU' => 'Vanuatu',
302
            'VE' => 'Venezuela',
303
            'VN' => 'Vietnam',
304
            'VG' => 'British Virgin Islands',
305
            'VI' => 'U.S. Virgin Islands',
306
            'WF' => 'Wallis & Futuna',
307
            'EH' => 'Western Sahara',
308
            'YE' => 'Yemen',
309
            'ZM' => 'Zambia',
310
            'ZW' => 'Zimbabwe',
311
        );
312
    }
313
}
314