GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CountryCodeListing   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 293
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 293
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A asArray() 0 12 2
A isPreferredChoice() 0 4 1
A isValidCountryCode() 0 4 1
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupBundle\Value\PhoneNumber;
20
21
class CountryCodeListing
22
{
23
    /**
24
     * The preferred choice to display on forms. Currently The Netherlands (+31).
25
     */
26
    const PREFERRED_CHOICE = '31';
27
28
    /**
29
     * List of currently (2015-03-16) known and used country codes as per
30
     * {@see en.wikipedia.org/wiki/List_of_country_calling_codes}
31
     *
32
     * Due to the fact that a single country can have multiple codes (e.g. Abkhazia) and that a single code
33
     * can be linked to multiple countries (e.g. '+1' -> US and Canada) we use the formal definition linked to
34
     * the actual code.
35
     *
36
     * When updating, update CountryCodeListing::$countryCodes to match.
37
     *
38
     * @var array
39
     */
40
    private static $countries = [
41
        'Abkhazia (+7 840)'                                   => '7840',
42
        'Abkhazia (+7 940)'                                   => '7940',
43
        'Afghanistan (+93)'                                   => '93',
44
        'Albania (+355)'                                      => '355',
45
        'Algeria (+213)'                                      => '213',
46
        'American Samoa (+1 684)'                             => '1684',
47
        'Andorra (+376)'                                      => '376',
48
        'Angola (+244)'                                       => '244',
49
        'Anguilla (+1 264)'                                   => '1264',
50
        'Antigua and Barbuda (+1 268)'                        => '1268',
51
        'Argentina (+54)'                                     => '54',
52
        'Armenia (+374)'                                      => '374',
53
        'Aruba (+297)'                                        => '297',
54
        'Ascension (+247)'                                    => '247',
55
        'Australia (+61)'                                     => '61',
56
        'Australian External Territories (+672)'              => '672',
57
        'Austria (+43)'                                       => '43',
58
        'Azerbaijan (+994)'                                   => '994',
59
        'Bahamas (+1 242)'                                    => '1242',
60
        'Bahrain (+973)'                                      => '973',
61
        'Bangladesh (+880)'                                   => '880',
62
        'Barbados (+1 246)'                                   => '1246',
63
        'Barbuda (+1 268)'                                    => '1268',
64
        'Belarus (+375)'                                      => '375',
65
        'Belgium (+32)'                                       => '32',
66
        'Belize (+501)'                                       => '501',
67
        'Benin (+229)'                                        => '229',
68
        'Bermuda (+1 441)'                                    => '1441',
69
        'Bhutan (+975)'                                       => '975',
70
        'Bolivia (+591)'                                      => '591',
71
        'Bosnia and Herzegovina (+387)'                       => '387',
72
        'Botswana (+267)'                                     => '267',
73
        'Brazil (+55)'                                        => '55',
74
        'British Indian Ocean Territory (+246)'               => '246',
75
        'British Virgin Islands (+1 284)'                     => '1284',
76
        'Brunei (+673)'                                       => '673',
77
        'Bulgaria (+359)'                                     => '359',
78
        'Burkina Faso (+226)'                                 => '226',
79
        'Burundi (+257)'                                      => '257',
80
        'Cambodia (+855)'                                     => '855',
81
        'Cameroon (+237)'                                     => '237',
82
        'Canada (+1)'                                         => '1',
83
        'Cape Verde (+238)'                                   => '238',
84
        'Cayman Islands (+ 345)'                              => '345',
85
        'Central African Republic (+236)'                     => '236',
86
        'Chad (+235)'                                         => '235',
87
        'Chile (+56)'                                         => '56',
88
        'China (+86)'                                         => '86',
89
        'Christmas Island (+61)'                              => '61',
90
        'Cocos-Keeling Islands (+61)'                         => '61',
91
        'Colombia (+57)'                                      => '57',
92
        'Comoros (+269)'                                      => '269',
93
        'Congo (+242)'                                        => '242',
94
        'Congo, Dem. Rep. of (Zaire) (+243)'                  => '243',
95
        'Cook Islands (+682)'                                 => '682',
96
        'Costa Rica (+506)'                                   => '506',
97
        'Ivory Coast (+225)'                                  => '225',
98
        'Croatia (+385)'                                      => '385',
99
        'Cuba (+53)'                                          => '53',
100
        'Curacao (+599)'                                      => '599',
101
        'Cyprus (+537)'                                       => '537',
102
        'Czech Republic (+420)'                               => '420',
103
        'Denmark (+45)'                                       => '45',
104
        'Diego Garcia (+246)'                                 => '246',
105
        'Djibouti (+253)'                                     => '253',
106
        'Dominica (+1 767)'                                   => '1767',
107
        'Dominican Republic (+1 809)'                         => '1809',
108
        'Dominican Republic (+1 829)'                         => '1829',
109
        'Dominican Republic (+1 849)'                         => '1849',
110
        'East Timor (+670)'                                   => '670',
111
        'Easter Island (+56)'                                 => '56',
112
        'Ecuador (+593)'                                      => '593',
113
        'Egypt (+20)'                                         => '20',
114
        'El Salvador (+503)'                                  => '503',
115
        'Equatorial Guinea (+240)'                            => '240',
116
        'Eritrea (+291)'                                      => '291',
117
        'Estonia (+372)'                                      => '372',
118
        'Ethiopia (+251)'                                     => '251',
119
        'Falkland Islands (+500)'                             => '500',
120
        'Faroe Islands (+298)'                                => '298',
121
        'Fiji (+679)'                                         => '679',
122
        'Finland (+358)'                                      => '358',
123
        'France (+33)'                                        => '33',
124
        'French Antilles (+596)'                              => '596',
125
        'French Guiana (+594)'                                => '594',
126
        'French Polynesia (+689)'                             => '689',
127
        'Gabon (+241)'                                        => '241',
128
        'Gambia (+220)'                                       => '220',
129
        'Georgia (+995)'                                      => '995',
130
        'Germany (+49)'                                       => '49',
131
        'Ghana (+233)'                                        => '233',
132
        'Gibraltar (+350)'                                    => '350',
133
        'Greece (+30)'                                        => '30',
134
        'Greenland (+299)'                                    => '299',
135
        'Grenada (+1 473)'                                    => '1473',
136
        'Guadeloupe (+590)'                                   => '590',
137
        'Guam (+1 671)'                                       => '1671',
138
        'Guatemala (+502)'                                    => '502',
139
        'Guinea (+224)'                                       => '224',
140
        'Guinea-Bissau (+245)'                                => '245',
141
        'Guyana (+595)'                                       => '595',
142
        'Haiti (+509)'                                        => '509',
143
        'Honduras (+504)'                                     => '504',
144
        'Hong Kong SAR China (+852)'                          => '852',
145
        'Hungary (+36)'                                       => '36',
146
        'Iceland (+354)'                                      => '354',
147
        'India (+91)'                                         => '91',
148
        'Indonesia (+62)'                                     => '62',
149
        'Iran (+98)'                                          => '98',
150
        'Iraq (+964)'                                         => '964',
151
        'Ireland (+353)'                                      => '353',
152
        'Israel (+972)'                                       => '972',
153
        'Italy (+39)'                                         => '39',
154
        'Jamaica (+1 876)'                                    => '1876',
155
        'Japan (+81)'                                         => '81',
156
        'Jordan (+962)'                                       => '962',
157
        'Kazakhstan (+76)'                                    => '76',
158
        'Kazakhstan (+77)'                                    => '77',
159
        'Kenya (+254)'                                        => '254',
160
        'Kiribati (+686)'                                     => '686',
161
        'North Korea (+850)'                                  => '850',
162
        'South Korea (+82)'                                   => '82',
163
        'Kuwait (+965)'                                       => '965',
164
        'Kyrgyzstan (+996)'                                   => '996',
165
        'Laos (+856)'                                         => '856',
166
        'Latvia (+371)'                                       => '371',
167
        'Lebanon (+961)'                                      => '961',
168
        'Lesotho (+266)'                                      => '266',
169
        'Liberia (+231)'                                      => '231',
170
        'Libya (+218)'                                        => '218',
171
        'Liechtenstein (+423)'                                => '423',
172
        'Lithuania (+370)'                                    => '370',
173
        'Luxembourg (+352)'                                   => '352',
174
        'Macau SAR China (+853)'                              => '853',
175
        'Macedonia (+389)'                                    => '389',
176
        'Madagascar (+261)'                                   => '261',
177
        'Malawi (+265)'                                       => '265',
178
        'Malaysia (+60)'                                      => '60',
179
        'Maldives (+960)'                                     => '960',
180
        'Mali (+223)'                                         => '223',
181
        'Malta (+356)'                                        => '356',
182
        'Marshall Islands (+692)'                             => '692',
183
        'Martinique (+596)'                                   => '596',
184
        'Mauritania (+222)'                                   => '222',
185
        'Mauritius (+230)'                                    => '230',
186
        'Mayotte (+262)'                                      => '262',
187
        'Mexico (+52)'                                        => '52',
188
        'Micronesia (+691)'                                   => '691',
189
        'Midway Island (+1 808)'                              => '1808',
190
        'Moldova (+373)'                                      => '373',
191
        'Monaco (+377)'                                       => '377',
192
        'Mongolia (+976)'                                     => '976',
193
        'Montenegro (+382)'                                   => '382',
194
        'Montserrat (+1664)'                                  => '1664',
195
        'Morocco (+212)'                                      => '212',
196
        'Myanmar (+95)'                                       => '95',
197
        'Namibia (+264)'                                      => '264',
198
        'Nauru (+674)'                                        => '674',
199
        'Nepal (+977)'                                        => '977',
200
        'Netherlands (+31)'                                   => '31',
201
        'Netherlands Antilles (+599)'                         => '599',
202
        'Nevis (+1 869)'                                      => '1869',
203
        'New Caledonia (+687)'                                => '687',
204
        'New Zealand (64)'                                    => '64',
205
        'Nicaragua (+505)'                                    => '505',
206
        'Niger (+227)'                                        => '227',
207
        'Nigeria (+234)'                                      => '234',
208
        'Niue (+683)'                                         => '683',
209
        'Norfolk Island (+672)'                               => '672',
210
        'Northern Mariana Islands (+1 670)'                   => '1670',
211
        'Norway (+47)'                                        => '47',
212
        'Oman (+968)'                                         => '968',
213
        'Pakistan (+92)'                                      => '92',
214
        'Palau (+680)'                                        => '680',
215
        'Palestinian Territory (+970)'                        => '970',
216
        'Panama (+507)'                                       => '507',
217
        'Papua New Guinea (+675)'                             => '675',
218
        'Paraguay (+595)'                                     => '595',
219
        'Peru (+51)'                                          => '51',
220
        'Philippines (+63)'                                   => '63',
221
        'Poland (+48)'                                        => '48',
222
        'Portugal (+351)'                                     => '351',
223
        'Puerto Rico (+1 787)'                                => '1787',
224
        'Puerto Rico (+1 939)'                                => '1939',
225
        'Qatar (+974)'                                        => '974',
226
        'Reunion (+262)'                                      => '262',
227
        'Romania (+40)'                                       => '40',
228
        'Russia (+7)'                                         => '7',
229
        'Rwanda (+250)'                                       => '250',
230
        'Samoa (+685)'                                        => '685',
231
        'San Marino (+378)'                                   => '378',
232
        'Saudi Arabia (+966)'                                 => '966',
233
        'Senegal (+221)'                                      => '221',
234
        'Serbia (+381)'                                       => '381',
235
        'Seychelles (+248)'                                   => '248',
236
        'Sierra Leone (+232)'                                 => '232',
237
        'Singapore (+65)'                                     => '65',
238
        'Slovakia (+421)'                                     => '421',
239
        'Slovenia (+386)'                                     => '386',
240
        'Solomon Islands (+677)'                              => '677',
241
        'South Africa (+27)'                                  => '27',
242
        'South Georgia and the South Sandwich Islands (+500)' => '500',
243
        'Spain (+34)'                                         => '34',
244
        'Sri Lanka (+94)'                                     => '94',
245
        'Sudan (+249)'                                        => '249',
246
        'Suriname (+597)'                                     => '597',
247
        'Swaziland (+268)'                                    => '268',
248
        'Sweden (+46)'                                        => '46',
249
        'Switzerland (+41)'                                   => '41',
250
        'Syria (+963)'                                        => '963',
251
        'Taiwan (+886)'                                       => '886',
252
        'Tajikistan (+992)'                                   => '992',
253
        'Tanzania (+255)'                                     => '255',
254
        'Thailand (+66)'                                      => '66',
255
        'Timor Leste (+670)'                                  => '670',
256
        'Togo (+228)'                                         => '228',
257
        'Tokelau (+690)'                                      => '690',
258
        'Tonga (+676)'                                        => '676',
259
        'Trinidad and Tobago (+1 868)'                        => '1868',
260
        'Tunisia (+216)'                                      => '216',
261
        'Turkey (+90)'                                        => '90',
262
        'Turkmenistan (+993)'                                 => '993',
263
        'Turks and Caicos Islands (+1 649)'                   => '1649',
264
        'Tuvalu (+688)'                                       => '688',
265
        'Uganda (+256)'                                       => '256',
266
        'Ukraine (+380)'                                      => '380',
267
        'United Arab Emirates (+971)'                         => '971',
268
        'United Kingdom (+44)'                                => '44',
269
        'United States (+1)'                                  => '1',
270
        'Uruguay (+598)'                                      => '598',
271
        'U.S. Virgin Islands (+1 340)'                        => '1340',
272
        'Uzbekistan (+998)'                                   => '998',
273
        'Vanuatu (+678)'                                      => '678',
274
        'Venezuela (+58)'                                     => '58',
275
        'Vietnam (+84)'                                       => '84',
276
        'Wake Island (+1 808)'                                => '1808',
277
        'Wallis and Futuna (+681)'                            => '681',
278
        'Yemen (+967)'                                        => '967',
279
        'Zambia (+260)'                                       => '260',
280
        'Zanzibar (+255)'                                     => '255',
281
        'Zimbabwe (+263)'                                     => '263',
282
    ];
283
284
    public static function asArray()
285
    {
286
        $countries = [];
287
288
        foreach (self::$countries as $name => $code) {
289
            $countries[] = new Country(new CountryCode($code), $name);
290
        }
291
292
        $countryNames = array_keys(self::$countries);
293
294
        return array_combine($countryNames, $countries);
295
    }
296
    /**
297
     * @param Country $country
298
     * @return bool
299
     */
300
    public static function isPreferredChoice(Country $country)
301
    {
302
        return $country->getCountryCode()->equals(new CountryCode(self::PREFERRED_CHOICE));
303
    }
304
305
    /**
306
     * @param string $countryCode
307
     * @return bool
308
     */
309
    public static function isValidCountryCode($countryCode)
310
    {
311
        return in_array($countryCode, self::$countries);
312
    }
313
}
314