Passed
Branch master (eaa143)
by Stefan
04:52
created

CAT   A

Complexity

Total Complexity 35

Size/Duplication

Total Lines 529
Duplicated Lines 1.51 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 8
loc 529
rs 9
c 0
b 0
f 0
wmc 35
lcom 1
cbo 3

6 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 291 5
A totalIdPs() 0 19 4
C listAllIdentityProviders() 0 63 11
A printCountryList() 4 19 4
C getExternalDBEntityDetails() 0 30 8
A getExternalCountriesList() 4 17 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * ******************************************************************************
5
 * Copyright 2011-2017 DANTE Ltd. and GÉANT on behalf of the GN3, GN3+, GN4-1 
6
 * and GN4-2 consortia
7
 *
8
 * License: see the web/copyright.php file in the file structure
9
 * ******************************************************************************
10
 */
11
12
/**
13
 * 
14
 * 
15
 *  This is the definition of the CAT class
16
 * @author Stefan Winter <[email protected]>
17
 * @author Tomasz Wolniewicz <[email protected]>
18
 *
19
 * @package Developer
20
 */
21
/**
22
 * necessary includes
23
 */
24
25
namespace core;
26
27
if (session_status() != PHP_SESSION_ACTIVE) {
28
    session_start();
29
}
30
31
/**
32
 * Define some variables which need to be globally accessible
33
 * and some general purpose methods
34
 *
35
 * @author Stefan Winter <[email protected]>
36
 * @author Tomasz Wolniewicz <[email protected]>
37
 *
38
 * @package Developer
39
 */
40
class CAT extends \core\common\Entity {
41
42
    /**
43
     * which version is this?
44
     * even if we are unreleased, keep track of internal version-to-be
45
     * developers need to set this in code. The user-displayed string
46
     * is generated into $CAT_VERSION_STRING and $CAT_COPYRIGHT below
47
     */
48
    const VERSION_MAJOR = 2;
49
    const VERSION_MINOR = 0;
50
    const VERSION_PATCH = 0;
51
    const VERSION_EXTRA = "pre-alpha1";
52
    const RELEASE_VERSION = FALSE;
53
    const USER_API_VERSION = 2;
54
55
    /**
56
     * trying to keep up with the name changes of copyright holder and consortia
57
     * updating those on *one* place should change display everywhere!
58
     */
59
    const COPYRIGHT_HOLDER = "DANTE Ltd. and G&Eacute;ANT";
60
    const COPYRIGHT_CONSORTIA = "the GN3, GN3+, GN4-1 and GN4-2 consortia";
61
    const COPYRIGHT_MIN_YEAR = 2011;
62
    const COPYRIGHT_MAX_YEAR = 2017;
63
64
    /*
65
     * This is the user-displayed string; controlled by the four options above
66
     * It is generated in the constructor.
67
     * 
68
     * @var string
69
     */
70
71
    public $CAT_VERSION_STRING;
72
73
    /*
74
     * The entire copyright line, generated in constructor
75
     */
76
    public $CAT_COPYRIGHT;
77
78
    /**
79
     * the custom displayable variant of the term 'federation'
80
     * @var string
81
     */
82
    public $nomenclature_fed;
83
84
    /**
85
     * the custom displayable variant of the term 'institution'
86
     * @var string
87
     */
88
    public $nomenclature_inst;
89
90
    /**
91
     * all known federation, in an array with ISO short name as an index, and localised version of the pretty-print name as value.
92
     * The static value is only filled with meaningful content after the first object has been instantiated. That is because it is not
93
     * possible to define static properties with function calls like _().
94
     * 
95
     * @var array of all known federations
96
     */
97
    public $knownFederations;
98
99
    /**
100
     * the default database to query in this class.
101
     */
102
    const DB_TYPE = "INST";
103
104
    /**
105
     *  Constructor sets the language by calling set_lang 
106
     *  and stores language settings in object properties
107
     *  additionally it also sets static variables $laing_index and $root
108
     */
109
    public function __construct() {
110
        parent::__construct();
111
        $olddomain = $this->languageInstance->setTextDomain("user");
112
        $this->CAT_VERSION_STRING = _("Unreleased <a href='https://github.com/GEANT/CAT/tree/master/Changes.md'>Git Revision</a>");
113
        if (CAT::RELEASE_VERSION) {
114
            $temp_version = "CAT-" . CAT::VERSION_MAJOR . "." . CAT::VERSION_MINOR;
115
            $branch = "release_" . CAT::VERSION_MAJOR . "_" . CAT::VERSION_MINOR;
116
            if (CAT::VERSION_PATCH != 0) {
117
                $temp_version .= "." . CAT::VERSION_PATCH;
118
            }
119
            if (CAT::VERSION_EXTRA != "") {
120
                $temp_version .= "-" . CAT::VERSION_EXTRA;
121
            }
122
            $this->CAT_VERSION_STRING = sprintf(_("Release <a href='%s'>%s</a>"), "https://github.com/GEANT/CAT/tree/" . $branch . "/Changes.md", $temp_version);
123
        }
124
        $this->CAT_COPYRIGHT = CONFIG['APPEARANCE']['productname'] . " - " . $this->CAT_VERSION_STRING . " &copy; " . CAT::COPYRIGHT_MIN_YEAR . "-" . CAT::COPYRIGHT_MAX_YEAR . " " . CAT::COPYRIGHT_HOLDER . "<br/>on behalf of " . CAT::COPYRIGHT_CONSORTIA . "; and others <a href='copyright.php'>Full Copyright and Licenses</a>";
125
        $this->languageInstance->setTextDomain($olddomain);
126
127
        /* Federations are created in DB with bootstrapFederation, and listed via listFederations
128
         */
129
        $oldlocale = $this->languageInstance->setTextDomain('core');
130
131
        // some config elements are displayable. We need some dummies to 
132
        // translate the common values for them. If a deployment chooses a 
133
        // different wording, no translation, sorry
134
135
        $dummy_NRO = _("National Roaming Operator");
136
        $dummy_inst1 = _("identity provider");
137
        $dummy_inst2 = _("organisation");
138
        $dummy_inst3 = _("Identity Provider");
139
        // and do something useless with the strings so that there's no "unused" complaint
140
        if (strlen($dummy_NRO . $dummy_inst1 . $dummy_inst2 . $dummy_inst3) < 0 ) {
141
            throw new \Exception("Strings are usually not shorter than 0 characters. We've encountered a string blackhole.");
142
        }
143
144
        $this->nomenclature_fed = _(CONFIG_CONFASSISTANT['CONSORTIUM']['nomenclature_federation']);
145
        $this->nomenclature_inst = _(CONFIG_CONFASSISTANT['CONSORTIUM']['nomenclature_institution']);
146
147
        $this->knownFederations = [
148
            'AD' => _("Andorra"),
149
            'AT' => _("Austria"),
150
            'BE' => _("Belgium"),
151
            'BG' => _("Bulgaria"),
152
            'CY' => _("Cyprus"),
153
            'CZ' => _("Czech Republic"),
154
            'DK' => _("Denmark"),
155
            'EE' => _("Estonia"),
156
            'FI' => _("Finland"),
157
            'FR' => _("France"),
158
            'DE' => _("Germany"),
159
            'GR' => _("Greece"),
160
            'HR' => _("Croatia"),
161
            'IE' => _("Ireland"),
162
            'IS' => _("Iceland"),
163
            'IT' => _("Italy"),
164
            'HU' => _("Hungary"),
165
            'LU' => _("Luxembourg"),
166
            'LV' => _("Latvia"),
167
            'LT' => _("Lithuania"),
168
            'MK' => _("Macedonia"),
169
            'RS' => _("Serbia"),
170
            'NL' => _("Netherlands"),
171
            'NO' => _("Norway"),
172
            'PL' => _("Poland"),
173
            'PT' => _("Portugal"),
174
            'RO' => _("Romania"),
175
            'SI' => _("Slovenia"),
176
            'ES' => _("Spain"),
177
            'SE' => _("Sweden"),
178
            'SK' => _("Slovakia"),
179
            'CH' => _("Switzerland"),
180
            'TR' => _("Turkey"),
181
            'UK' => _("United Kingdom"),
182
            'TEST' => 'TEST Country',
183
            'AU' => _("Australia"),
184
            'CA' => _("Canada"),
185
            'IL' => _("Israel"),
186
            'JP' => _("Japan"),
187
            'NZ' => _("New Zealand"),
188
            'US' => _("U.S.A."),
189
            'BR' => _("Brazil"),
190
            'CL' => _("Chile"),
191
            'PE' => _("Peru"),
192
            'VE' => _("Venezuela"),
193
            'DEFAULT' => _("Default"),
194
            'AM' => _("Armenia"),
195
            'AZ' => _("Azerbaijan"),
196
            'BY' => _("Belarus"),
197
            'EC' => _("Ecuador"),
198
            'HK' => _("Hong Kong"),
199
            'KE' => _("Kenya"),
200
            'KG' => _("Kyrgyzstan"),
201
            'KR' => _("Korea"),
202
            'KZ' => _("Kazakhstan"),
203
            'MA' => _("Morocco"),
204
            'MD' => _("Moldova"),
205
            'ME' => _("Montenegro"),
206
            'MO' => _("Macau"),
207
            'MT' => _("Malta"),
208
            'RU' => _("Russia"),
209
            'SG' => _("Singapore"),
210
            'TH' => _("Thailand"),
211
            'TW' => _("Taiwan"),
212
            'ZA' => _("South Africa"),
213
            'AF' => 'Afghanistan',
214
            'AL' => 'Albania',
215
            'DZ' => 'Algeria',
216
            'AS' => 'American Samoa',
217
            'AO' => 'Angola',
218
            'AI' => 'Anguilla',
219
            'AQ' => 'Antarctica',
220
            'AG' => 'Antigua And Barbuda',
221
            'AR' => 'Argentina',
222
            'AW' => 'Aruba',
223
            'BS' => 'Bahamas, The',
224
            'BH' => 'Bahrain',
225
            'BD' => 'Bangladesh',
226
            'BB' => 'Barbados',
227
            'BZ' => 'Belize',
228
            'BJ' => 'Benin',
229
            'BM' => 'Bermuda',
230
            'BT' => 'Bhutan',
231
            'BO' => 'Bolivia',
232
            'BA' => 'Bosnia And Herzegovina',
233
            'BW' => 'Botswana',
234
            'BV' => 'Bouvet Island',
235
            'IO' => 'British Indian Ocean Territory',
236
            'BN' => 'Brunei',
237
            'BF' => 'Burkina Faso',
238
            'MM' => 'Burma',
239
            'BI' => 'Burundi',
240
            'KH' => 'Cambodia',
241
            'CM' => 'Cameroon',
242
            'CV' => 'Cape Verde',
243
            'KY' => 'Cayman Islands',
244
            'CF' => 'Central African Republic',
245
            'TD' => 'Chad',
246
            'CN' => 'China',
247
            'CX' => 'Christmas Island',
248
            'CC' => 'Cocos (keeling) Islands',
249
            'CO' => 'Colombia',
250
            'KM' => 'Comoros',
251
            'CG' => 'Congo (brazzaville) ',
252
            'CD' => 'Congo (kinshasa)',
253
            'CK' => 'Cook Islands',
254
            'CR' => 'Costa Rica',
255
            'CI' => 'CÔte D’ivoire',
256
            'CU' => 'Cuba',
257
            'CW' => 'CuraÇao',
258
            'DJ' => 'Djibouti',
259
            'DM' => 'Dominica',
260
            'DO' => 'Dominican Republic',
261
            'EG' => 'Egypt',
262
            'SV' => 'El Salvador',
263
            'GQ' => 'Equatorial Guinea',
264
            'ER' => 'Eritrea',
265
            'ET' => 'Ethiopia',
266
            'FK' => 'Falkland Islands (islas Malvinas)',
267
            'FO' => 'Faroe Islands',
268
            'FJ' => 'Fiji',
269
            'GF' => 'French Guiana',
270
            'PF' => 'French Polynesia',
271
            'TF' => 'French Southern And Antarctic Lands',
272
            'GA' => 'Gabon',
273
            'GM' => 'Gambia, The',
274
            'GE' => 'Georgia',
275
            'GEANT' => 'The GEANT country',
276
            'GH' => 'Ghana',
277
            'GI' => 'Gibraltar',
278
            'GL' => 'Greenland',
279
            'GD' => 'Grenada',
280
            'GP' => 'Guadeloupe',
281
            'GU' => 'Guam',
282
            'GT' => 'Guatemala',
283
            'GG' => 'Guernsey',
284
            'GN' => 'Guinea',
285
            'GW' => 'Guinea-bissau',
286
            'GY' => 'Guyana',
287
            'HT' => 'Haiti',
288
            'HM' => 'Heard Island And Mcdonald Islands',
289
            'HN' => 'Honduras',
290
            'IN' => 'India',
291
            'ID' => 'Indonesia',
292
            'IR' => 'Iran',
293
            'IQ' => 'Iraq',
294
            'IM' => 'Isle Of Man',
295
            'JM' => 'Jamaica',
296
            'JE' => 'Jersey',
297
            'JO' => 'Jordan',
298
            'KI' => 'Kiribati',
299
            'KP' => 'Korea, North',
300
            'KW' => 'Kuwait',
301
            'LA' => 'Laos',
302
            'LB' => 'Lebanon',
303
            'LS' => 'Lesotho',
304
            'LR' => 'Liberia',
305
            'LY' => 'Libya',
306
            'LI' => 'Liechtenstein',
307
            'MG' => 'Madagascar',
308
            'MW' => 'Malawi',
309
            'MY' => 'Malaysia',
310
            'MV' => 'Maldives',
311
            'ML' => 'Mali',
312
            'MH' => 'Marshall Islands',
313
            'MQ' => 'Martinique',
314
            'MR' => 'Mauritania',
315
            'MU' => 'Mauritius',
316
            'YT' => 'Mayotte',
317
            'MX' => 'Mexico',
318
            'FM' => 'Micronesia, Federated States Of',
319
            'MC' => 'Monaco',
320
            'MN' => 'Mongolia',
321
            'MS' => 'Montserrat',
322
            'MZ' => 'Mozambique',
323
            'NA' => 'Namibia',
324
            'NR' => 'Nauru',
325
            'NP' => 'Nepal',
326
            'NC' => 'New Caledonia',
327
            'NI' => 'Nicaragua',
328
            'NE' => 'Niger',
329
            'NG' => 'Nigeria',
330
            'NU' => 'Niue',
331
            'NF' => 'Norfolk Island',
332
            'MP' => 'Northern Mariana Islands',
333
            'OM' => 'Oman',
334
            'PK' => 'Pakistan',
335
            'PW' => 'Palau',
336
            'PA' => 'Panama',
337
            'PG' => 'Papua New Guinea',
338
            'PY' => 'Paraguay',
339
            'PH' => 'Philippines',
340
            'PN' => 'Pitcairn Islands',
341
            'PR' => 'Puerto Rico',
342
            'QA' => 'Qatar',
343
            'RE' => 'Reunion',
344
            'RW' => 'Rwanda',
345
            'BL' => 'Saint Barthelemy',
346
            'SH' => 'Saint Helena, Ascension, And Tristan Da Cunha',
347
            'KN' => 'Saint Kitts And Nevis',
348
            'LC' => 'Saint Lucia',
349
            'MF' => 'Saint Martin',
350
            'PM' => 'Saint Pierre And Miquelon',
351
            'VC' => 'Saint Vincent And The Grenadines',
352
            'WS' => 'Samoa',
353
            'SM' => 'San Marino',
354
            'ST' => 'Sao Tome And Principe',
355
            'SA' => 'Saudi Arabia',
356
            'SN' => 'Senegal',
357
            'SC' => 'Seychelles',
358
            'SL' => 'Sierra Leone',
359
            'SX' => 'Sint Maarten',
360
            'SB' => 'Solomon Islands',
361
            'SO' => 'Somalia',
362
            'GS' => 'South Georgia And South Sandwich Islands',
363
            'SS' => 'South Sudan',
364
            'LK' => 'Sri Lanka',
365
            'SD' => 'Sudan',
366
            'SR' => 'Suriname',
367
            'SZ' => 'Swaziland',
368
            'SY' => 'Syria',
369
            'TJ' => 'Tajikistan',
370
            'TZ' => 'Tanzania',
371
            'TL' => 'Timor-leste',
372
            'TG' => 'Togo',
373
            'TK' => 'Tokelau',
374
            'TO' => 'Tonga',
375
            'TT' => 'Trinidad And Tobago',
376
            'TN' => 'Tunisia',
377
            'TM' => 'Turkmenistan',
378
            'TC' => 'Turks And Caicos Islands',
379
            'TV' => 'Tuvalu',
380
            'UG' => 'Uganda',
381
            'UA' => 'Ukraine',
382
            'AE' => 'United Arab Emirates',
383
            'GB' => 'United Kingdom',
384
            'UY' => 'Uruguay',
385
            'UZ' => 'Uzbekistan',
386
            'VU' => 'Vanuatu',
387
            'VA' => 'Vatican City',
388
            'VN' => 'Vietnam',
389
            'VG' => 'Virgin Islands, British',
390
            'VI' => 'Virgin Islands, United States ',
391
            'WF' => 'Wallis And Futuna',
392
            'EH' => 'Western Sahara',
393
            'YE' => 'Yemen',
394
            'ZM' => 'Zambia',
395
            'ZW' => 'Zimbabwe',
396
        ];
397
398
        $this->languageInstance->setTextDomain($oldlocale);
399
    }
400
401
    /**
402
     * 
403
     */
404
    public function totalIdPs($level) {
405
        $handle = DBConnection::handle(CAT::DB_TYPE);
406
        switch ($level) {
407
            case "ALL":
408
                $idpcount = $handle->exec("SELECT COUNT(inst_id) AS instcount FROM institution");
409
                break;
410
            case "VALIDPROFILE":
411
                $idpcount = $handle->exec("SELECT COUNT(DISTINCT institution.inst_id) AS instcount FROM institution,profile WHERE institution.inst_id = profile.inst_id AND profile.sufficient_config = 1");
412
                break;
413
            case "PUBLICPROFILE":
414
                $idpcount = $handle->exec("SELECT COUNT(DISTINCT institution.inst_id) AS instcount FROM institution,profile WHERE institution.inst_id = profile.inst_id AND profile.showtime = 1");
415
                break;
416
            default:
417
                return -1;
418
        }
419
        // SELECTs never return a booleans, always an object
420
        $dbresult = mysqli_fetch_object(/** @scrutinizer ignore-type */ $idpcount);
421
        return $dbresult->instcount;
422
    }
423
424
    /**
425
     * Lists all identity providers in the database
426
     * adding information required by DiscoJuice.
427
     * @param int $activeOnly if and set to non-zero will
428
     * cause listing of only those institutions which have some valid profiles defined.
429
     *
430
     */
431
    public function listAllIdentityProviders($activeOnly = 0, $country = 0) {
432
        $handle = DBConnection::handle("INST");
433
        $handle->exec("SET SESSION group_concat_max_len=10000");
434
        $query = "SELECT distinct institution.inst_id AS inst_id, institution.country AS country,
435
                     group_concat(concat_ws('===',institution_option.option_name,LEFT(institution_option.option_value,200), institution_option.option_lang) separator '---') AS options
436
                     FROM institution ";
437
        if ($activeOnly == 1) {
438
            $query .= "JOIN v_active_inst ON institution.inst_id = v_active_inst.inst_id ";
439
        }
440
        $query .= "JOIN institution_option ON institution.inst_id = institution_option.institution_id ";
441
        $query .= "WHERE (institution_option.option_name = 'general:instname' 
442
                          OR institution_option.option_name = 'general:geo_coordinates'
443
                          OR institution_option.option_name = 'general:logo_file') ";
444
445
        $query .= ($country ? "AND institution.country = ? " : "");
446
447
        $query .= "GROUP BY institution.inst_id ORDER BY inst_id";
448
        
449
        $allIDPs = ($country ? $handle->exec($query, "s", $country) : $handle->exec($query));
450
        $returnarray = [];
451
        // SELECTs never return a booleans, always an object
452
        while ($queryResult = mysqli_fetch_object(/** @scrutinizer ignore-type */ $allIDPs)) {
453
            $institutionOptions = explode('---', $queryResult->options);
454
            $oneInstitutionResult = [];
455
            $geo = [];
456
            $names = [];
457
458
            $oneInstitutionResult['entityID'] = $queryResult->inst_id;
459
            $oneInstitutionResult['country'] = strtoupper($queryResult->country);
460
            foreach ($institutionOptions as $institutionOption) {
461
                $opt = explode('===', $institutionOption);
462
                switch ($opt[0]) {
463
                    case 'general:logo_file':
464
                        $oneInstitutionResult['icon'] = $queryResult->inst_id;
465
                        break;
466
                    case 'general:geo_coordinates':
467
                        $at1 = json_decode($opt[1], true);
468
                        $geo[] = $at1;
469
                        break;
470
                    case 'general:instname':
471
                        $names[] = [
472
                            'lang' => $opt[2],
473
                            'value' => $opt[1]
474
                        ];
475
                        break;
476
                    default:
477
                        break;
478
                }
479
            }
480
481
            $name = _("Unnamed Entity");
482
            if (count($names) != 0) {
483
                $langObject = new \core\common\Language();
484
                $name = $langObject->getLocalisedValue($names);
485
            }
486
            $oneInstitutionResult['title'] = $name;
487
            if (count($geo) > 0) {
488
                $oneInstitutionResult['geo'] = $geo;
489
            }
490
            $returnarray[] = $oneInstitutionResult;
491
        }
492
        return $returnarray;
493
    }
494
495
    /**
496
     * Prepares a list of countries known to the CAT.
497
     * 
498
     * @param int $activeOnly is set and nonzero will cause that only countries with some institutions underneath will be listed
499
     * @return array Array indexed by (uppercase) lang codes and sorted according to the current locale
500
     */
501
    public function printCountryList($activeOnly = 0) {
502
        $olddomain = $this->languageInstance->setTextDomain("core");
503
        $handle = DBConnection::handle(CAT::DB_TYPE);
504
        $returnArray = []; // in if -> the while might never be executed, so initialise
505
        if ($activeOnly) {
506
            $federations = $handle->exec("SELECT DISTINCT UPPER(institution.country) AS country FROM institution JOIN profile
507
                          ON institution.inst_id = profile.inst_id WHERE profile.showtime = 1 ORDER BY country");
508
            // SELECT never returns a boolean, always a mysqli_object
509 View Code Duplication
            while ($activeFederations = mysqli_fetch_object(/** @scrutinizer ignore-type */ $federations)) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
510
                $fedIdentifier = $activeFederations->country; // UPPER() has capitalised this for us
511
                $returnArray[$fedIdentifier] = isset($this->knownFederations[$fedIdentifier]) ? $this->knownFederations[$fedIdentifier] : $fedIdentifier;
512
            }
513
        } else {
514
            $returnArray = $this->knownFederations;
515
        }
516
        asort($returnArray, SORT_LOCALE_STRING);
517
        $this->languageInstance->setTextDomain($olddomain);
518
        return($returnArray);
519
    }
520
521
    public function getExternalDBEntityDetails($externalId, $realm = NULL) {
522
        $list = [];
523
        if (CONFIG_CONFASSISTANT['CONSORTIUM']['name'] == "eduroam" && isset(CONFIG_CONFASSISTANT['CONSORTIUM']['deployment-voodoo']) && CONFIG_CONFASSISTANT['CONSORTIUM']['deployment-voodoo'] == "Operations Team") { // SW: APPROVED
524
            $scanforrealm = "";
525
            if ($realm !== NULL) {
526
                $scanforrealm = "OR inst_realm LIKE '%$realm%'";
527
            }
528
            $externalHandle = DBConnection::handle("EXTERNAL");
529
            $infoList = $externalHandle->exec("SELECT name AS collapsed_name, inst_realm as realmlist, contact AS collapsed_contact, country FROM view_active_idp_institution WHERE id_institution = $externalId $scanforrealm");
530
            // split names and contacts into proper pairs
531
            // SELECT never returns a boolean, always a mysqli_object
532
            while ($externalEntityQuery = mysqli_fetch_object(/** @scrutinizer ignore-type */ $infoList)) {
533
                $names = explode('#', $externalEntityQuery->collapsed_name);
534
                foreach ($names as $name) {
535
                    $perlang = explode(': ', $name, 2);
536
                    $list['names'][$perlang[0]] = $perlang[1];
537
                }
538
                $contacts = explode('#', $externalEntityQuery->collapsed_contact);
539
                foreach ($contacts as $contact) {
540
                    $email1 = explode('e: ', $contact);
541
                    $email2 = explode(',', $email1[1]);
542
                    $list['admins'][] = ["email" => $email2[0]];
543
                }
544
                $list['country'] = strtoupper($externalEntityQuery->country);
545
                $list['realmlist'] = $externalEntityQuery->realmlist;
546
            }
547
        }
548
        return $list;
549
        
550
    }
551
    public function getExternalCountriesList() {
552
        $olddomain = $this->languageInstance->setTextDomain("core");
553
        $handle = DBConnection::handle("EXTERNAL");
554
        $returnArray = []; // in if -> the while might never be executed, so initialise
555
        $timeStart = microtime(true);
556
        $federations = $handle->exec("SELECT DISTINCT UPPER(country) AS country FROM view_active_idp_institution ORDER BY country");
557
        $timeEnd = microtime(true);
558
        $timeElapsed = $timeEnd - $timeStart;
559 View Code Duplication
        while ($eduroamFederations = mysqli_fetch_object($federations)) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
560
            $fedIdentifier = $eduroamFederations->country;
561
            $returnArray[$fedIdentifier] = isset($this->knownFederations[$fedIdentifier]) ? $this->knownFederations[$fedIdentifier] : $fedIdentifier;
562
        } 
563
        asort($returnArray, SORT_LOCALE_STRING);
564
        $returnArray['time'] = $timeElapsed;
565
        $this->languageInstance->setTextDomain($olddomain);
566
        return($returnArray);
567
    }
568
}
569