Skip to content

Commit c8107a2

Browse files
committed
Cast all returns from Config.php to appropriate types
- as per issue request, all returns from config.php are now explicitly cast to appropriate types - this is to prevent confusion and error as before returns were being cast as a SimpleXMLElement object which can cause unexpected behaviour - new lines were also added in and around some of the functions where they were missing to make the text more readable
1 parent f94e980 commit c8107a2

File tree

1 file changed

+77
-47
lines changed

1 file changed

+77
-47
lines changed

lib/Gocdb_Services/Config.php

Lines changed: 77 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -267,101 +267,132 @@ private function descendXml(\SimpleXmlIterator $iterator, $keys, \SimpleXmlEleme
267267
*/
268268
public function IsPortalReadOnly()
269269
{
270-
$localInfo = $this->GetLocalInfoXML();
271-
if (strtolower($localInfo->read_only) == 'true') {
270+
$portalReadOnly = (string) $this->GetLocalInfoXML()->read_only;
271+
if (strtolower($portalReadOnly) == 'true') {
272272
return true;
273273
}
274274

275275
return false;
276276
}
277+
277278
/**
278279
* returns the url of the Acceptable Use Policy for display on the landing page
279280
* @return string
280281
*/
281282
public function getAUP()
282283
{
283-
return $this->GetLocalInfoXML()->aup;
284+
$aup = (string) $this->GetLocalInfoXML()->aup;
285+
286+
return $aup;
284287
}
288+
285289
/**
286290
* returns the title string describing the Acceptable Use Policy for display on the landing page
287291
* @return string
288292
*/
289293
public function getAUPTitle()
290294
{
291-
return $this->GetLocalInfoXML()->aup_title;
295+
$aupTitle = (string) $this->GetLocalInfoXML()->aup_title;
296+
297+
return $aupTitle;
292298
}
299+
293300
/**
294301
* returns the url of the Privacy Notice for display on the landing page
295302
* @return string
296303
*/
297304
public function getPrivacyNotice()
298305
{
299-
return $this->GetLocalInfoXML()->privacy_notice;
306+
$privacyNotice = (string) $this->GetLocalInfoXML()->privacy_notice;
307+
308+
return $privacyNotice;
300309
}
310+
301311
/**
302312
* returns the title string describing the Privacy Notice for display on the landing page
303313
* @return string
304314
*/
305315
public function getPrivacyNoticeTitle()
306316
{
307-
return $this->GetLocalInfoXML()->privacy_notice_title;
317+
$privacyNoticeTitle = (string) $this->GetLocalInfoXML()->privacy_notice_title;
318+
319+
return $privacyNoticeTitle;
308320
}
321+
309322
/**
310323
* returns true if the given menu is to be shown according to local_info.xml
311324
* @return boolean
312325
*/
313326
public function showMenu($menuName)
314327
{
315-
316-
if (empty($this->GetLocalInfoXML()->menus->$menuName)) {
328+
$menuItem = (string) $this->GetLocalInfoXML()->menus->$menuName;
329+
if (empty($menuItem)) {
317330
return true;
318331
}
319332

320-
switch (strtolower((string) $this->GetLocalInfoXML()->menus->$menuName)) {
333+
switch (strtolower($menuItem)) {
321334
case 'false':
322335
case 'hide':
323336
case 'no':
324337
return false;
325338
}
326339
return true;
327340
}
341+
328342
/**
329343
* returns the relevant name mapping according to local_info.xml
330344
* @return string
331345
*/
332346
public function getNameMapping($entityType, $key)
333347
{
334-
if (empty($this->GetLocalInfoXML()->name_mapping->$entityType)) {
348+
$nameMapping = (string) $this->GetLocalInfoXML()->name_mapping->$entityType;
349+
if (empty($nameMapping)) {
335350
return $key;
336351
}
337352
switch ($entityType) {
338353
case 'Service':
339-
return $this->GetLocalInfoXML()->name_mapping->$entityType->{str_replace(' ', '', $key)};
354+
$service = (string) $this->GetLocalInfoXML()->name_mapping->$entityType->{str_replace(' ', '', $key)};
355+
return $service;
340356
}
341357
}
358+
342359
/**
343360
* accessor function for css colour values from local_info.xml
344361
* @return string
345362
*/
346363
public function getBackgroundDirection()
347364
{
348-
return $this->GetLocalInfoXML()->css->backgroundDirection;
365+
$backgroundDirection = (string) $this->GetLocalInfoXML()->css->backgroundDirection;
366+
367+
return $backgroundDirection;
349368
}
369+
350370
public function getBackgroundColour1()
351371
{
352-
return $this->GetLocalInfoXML()->css->backgroundColour1;
372+
$backgroundColour1 = (string) $this->GetLocalInfoXML()->css->backgroundColour1;
373+
374+
return $backgroundColour1;
353375
}
376+
354377
public function getBackgroundColour2()
355378
{
356-
return $this->GetLocalInfoXML()->css->backgroundColour2;
379+
$backgroundColour2 = (string) $this->GetLocalInfoXML()->css->backgroundColour2;
380+
381+
return $backgroundColour2;
357382
}
383+
358384
public function getBackgroundColour3()
359385
{
360-
return $this->GetLocalInfoXML()->css->backgroundColour3;
386+
$backgroundColour3 = (string) $this->GetLocalInfoXML()->css->backgroundColour3;
387+
388+
return $backgroundColour3;
361389
}
390+
362391
public function getHeadingTextColour()
363392
{
364-
return $this->GetLocalInfoXML()->css->headingTextColour;
393+
$headingTextColour = $this->GetLocalInfoXML()->css->headingTextColour;
394+
395+
return $headingTextColour;
365396
}
366397

367398
/**
@@ -372,9 +403,8 @@ public function getHeadingTextColour()
372403
*/
373404
public function IsOptionalFeatureSet($featureName)
374405
{
375-
$localInfo = $this->GetLocalInfoXML();
376-
$feature = $localInfo->optional_features->$featureName;
377-
if ((string) $feature == "true") {
406+
$feature = (string) $this->GetLocalInfoXML()->optional_features->$featureName;
407+
if ($feature == "true") {
378408
return true;
379409
} else {
380410
return false;
@@ -388,9 +418,8 @@ public function IsOptionalFeatureSet($featureName)
388418
*/
389419
public function GetPortalURL()
390420
{
391-
$localInfo = $this->GetLocalInfoXML();
392-
$url = $localInfo->web_portal_url;
393-
return strval($url);
421+
$portalUrl = (string) $this->GetLocalInfoXML()->web_portal_url;
422+
return $portalUrl;
394423
}
395424
/**
396425
* How Personal Data is restricted;
@@ -404,9 +433,8 @@ public function isRestrictPDByRole($forceStrict = false)
404433
if ($forceStrict === true)
405434
return true;
406435

407-
$localInfo = $this->GetLocalInfoXML();
408-
$value = $localInfo->restrict_personal_data;
409-
if ((string) $value == "true") {
436+
$value = (string) $this->GetLocalInfoXML()->restrict_personal_data;
437+
if ($value == "true") {
410438
return true;
411439
} else {
412440
return false;
@@ -417,9 +445,9 @@ public function isRestrictPDByRole($forceStrict = false)
417445
*/
418446
public function getPiUrl()
419447
{
420-
$localInfo = $this->GetLocalInfoXML();
421-
$url = $localInfo->pi_url;
422-
return strval($url);
448+
$piUrl = (string) $this->GetLocalInfoXML()->pi_url;
449+
450+
return $piUrl;
423451
}
424452

425453
/**
@@ -428,9 +456,9 @@ public function getPiUrl()
428456
*/
429457
public function getServerBaseUrl()
430458
{
431-
$localInfo = $this->GetLocalInfoXML();
432-
$url = $localInfo->server_base_url;
433-
return strval($url);
459+
$serverBaseUrl = (string) $this->GetLocalInfoXML()->server_base_url;
460+
461+
return $serverBaseUrl;
434462
}
435463

436464
/**
@@ -439,32 +467,32 @@ public function getServerBaseUrl()
439467
*/
440468
public function getWriteApiDocsUrl()
441469
{
442-
$localInfo = $this->GetLocalInfoXML();
443-
$url = $localInfo->write_api_user_docs_url;
444-
return strval($url);
470+
$writeApiDocsUrl = (string) $this->GetLocalInfoXML()->write_api_user_docs_url;
471+
472+
return $writeApiDocsUrl;
445473
}
446474

447475
public function getDefaultScopeName()
448476
{
449-
//$scopeName = $this->GetLocalInfoXML()->local_info->default_scope->name;
450-
$scopeName = $this->GetLocalInfoXML()->default_scope->name;
477+
//$scopeName = (string) $this->GetLocalInfoXML()->local_info->default_scope->name;
478+
$scopeName = (string) $this->GetLocalInfoXML()->default_scope->name;
451479

452480
if (empty($scopeName)) {
453481
$scopeName = '';
454482
}
455483

456-
return strval($scopeName);
484+
return $scopeName;
457485
}
458486

459487
public function getDefaultScopeMatch()
460488
{
461-
$scopeMatch = $this->GetLocalInfoXML()->default_scope_match;
489+
$scopeMatch = (string) $this->GetLocalInfoXML()->default_scope_match;
462490

463491
if (empty($scopeMatch)) {
464492
$scopeMatch = 'all';
465493
}
466494

467-
return strval($scopeMatch);
495+
return $scopeMatch;
468496
}
469497

470498
public function getMinimumScopesRequired($entityType)
@@ -475,13 +503,13 @@ public function getMinimumScopesRequired($entityType)
475503
throw new \LogicException("Function does not support entity type");
476504
}
477505

478-
$numScopesRequired = $this->GetLocalInfoXML()->minimum_scopes->$entityType;
506+
$numScopesRequired = (int) $this->GetLocalInfoXML()->minimum_scopes->$entityType;
479507

480508
if (empty($numScopesRequired)) {
481509
$numScopesRequired = 0;
482510
}
483511

484-
return intval($numScopesRequired);
512+
return $numScopesRequired;
485513
}
486514

487515
public function getDefaultFilterByScope()
@@ -496,7 +524,7 @@ public function getDefaultFilterByScope()
496524

497525
public function getShowMapOnStartPage()
498526
{
499-
$showMapString = $this->GetLocalInfoXML()->show_map_on_start_page;
527+
$showMapString = (string) $this->GetLocalInfoXML()->show_map_on_start_page;
500528

501529
if (empty($showMapString)) {
502530
$showMap = false;
@@ -511,13 +539,15 @@ public function getShowMapOnStartPage()
511539

512540
public function getExtensionsLimit()
513541
{
514-
return $this->GetLocalInfoXML()->extensions->max;
542+
$extensionsLimit = (int) $this->GetLocalInfoXML()->extensions->max;
543+
544+
return $extensionsLimit;
515545
}
516546

517547

518548
public function getSendEmails()
519549
{
520-
$sendEmailString = $this->GetLocalInfoXML()->send_email;
550+
$sendEmailString = (string) $this->GetLocalInfoXML()->send_email;
521551
if (empty($sendEmailString)) {
522552
$sendEmail = false;
523553
} elseif (strtolower($sendEmailString) == 'true') {
@@ -538,21 +568,21 @@ public function getAPIAllAuthRealms()
538568

539569
public function getPageBanner()
540570
{
541-
$bannerText = $this->GetLocalInfoXML()->page_banner;
571+
$bannerText = (string) $this->GetLocalInfoXML()->page_banner;
542572

543573
return $bannerText;
544574
}
545575

546576
public function getEmailFrom()
547577
{
548-
$emailFrom = $this->GetLocalInfoXML()->email_from;
578+
$emailFrom = (string) $this->GetLocalInfoXML()->email_from;
549579

550580
return $emailFrom;
551581
}
552582

553583
public function getEmailTo()
554584
{
555-
$emailTo = $this->GetlocalInfoXML()->email_to;
585+
$emailTo = (string) $this->GetlocalInfoXML()->email_to;
556586

557587
return $emailTo;
558588
}

0 commit comments

Comments
 (0)