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.
Completed
Push — master ( d4426a...04c02a )
by Boy
11:46 queued 08:30
created

CountryCodeListing   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 297
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 4
c 6
b 1
f 0
lcom 1
cbo 3
dl 0
loc 297
rs 10

3 Methods

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