Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GT-129 Cast all returns from Config.php to appropriate types #420

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 77 additions & 47 deletions lib/Gocdb_Services/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,101 +267,132 @@ private function descendXml(\SimpleXmlIterator $iterator, $keys, \SimpleXmlEleme
*/
public function IsPortalReadOnly()
{
$localInfo = $this->GetLocalInfoXML();
if (strtolower($localInfo->read_only) == 'true') {
$portalReadOnly = (string) $this->GetLocalInfoXML()->read_only;
if (strtolower($portalReadOnly) == 'true') {
return true;
}

return false;
}

/**
* returns the url of the Acceptable Use Policy for display on the landing page
* @return string
*/
public function getAUP()
{
return $this->GetLocalInfoXML()->aup;
$aup = (string) $this->GetLocalInfoXML()->aup;

return $aup;
}

/**
* returns the title string describing the Acceptable Use Policy for display on the landing page
* @return string
*/
public function getAUPTitle()
{
return $this->GetLocalInfoXML()->aup_title;
$aupTitle = (string) $this->GetLocalInfoXML()->aup_title;

return $aupTitle;
}

/**
* returns the url of the Privacy Notice for display on the landing page
* @return string
*/
public function getPrivacyNotice()
{
return $this->GetLocalInfoXML()->privacy_notice;
$privacyNotice = (string) $this->GetLocalInfoXML()->privacy_notice;

return $privacyNotice;
}

/**
* returns the title string describing the Privacy Notice for display on the landing page
* @return string
*/
public function getPrivacyNoticeTitle()
{
return $this->GetLocalInfoXML()->privacy_notice_title;
$privacyNoticeTitle = (string) $this->GetLocalInfoXML()->privacy_notice_title;

return $privacyNoticeTitle;
}

/**
* returns true if the given menu is to be shown according to local_info.xml
* @return boolean
*/
public function showMenu($menuName)
{

if (empty($this->GetLocalInfoXML()->menus->$menuName)) {
$menuItem = (string) $this->GetLocalInfoXML()->menus->$menuName;
if (empty($menuItem)) {
return true;
}

switch (strtolower((string) $this->GetLocalInfoXML()->menus->$menuName)) {
switch (strtolower($menuItem)) {
case 'false':
case 'hide':
case 'no':
return false;
}
return true;
}

/**
* returns the relevant name mapping according to local_info.xml
* @return string
*/
public function getNameMapping($entityType, $key)
{
if (empty($this->GetLocalInfoXML()->name_mapping->$entityType)) {
$nameMapping = (string) $this->GetLocalInfoXML()->name_mapping->$entityType;
if (empty($nameMapping)) {
return $key;
}
switch ($entityType) {
case 'Service':
return $this->GetLocalInfoXML()->name_mapping->$entityType->{str_replace(' ', '', $key)};
$service = (string) $this->GetLocalInfoXML()->name_mapping->$entityType->{str_replace(' ', '', $key)};
return $service;
}
}

/**
* accessor function for css colour values from local_info.xml
* @return string
*/
public function getBackgroundDirection()
{
return $this->GetLocalInfoXML()->css->backgroundDirection;
$backgroundDirection = (string) $this->GetLocalInfoXML()->css->backgroundDirection;

return $backgroundDirection;
}

public function getBackgroundColour1()
{
return $this->GetLocalInfoXML()->css->backgroundColour1;
$backgroundColour1 = (string) $this->GetLocalInfoXML()->css->backgroundColour1;

return $backgroundColour1;
}

public function getBackgroundColour2()
{
return $this->GetLocalInfoXML()->css->backgroundColour2;
$backgroundColour2 = (string) $this->GetLocalInfoXML()->css->backgroundColour2;

return $backgroundColour2;
}

public function getBackgroundColour3()
{
return $this->GetLocalInfoXML()->css->backgroundColour3;
$backgroundColour3 = (string) $this->GetLocalInfoXML()->css->backgroundColour3;

return $backgroundColour3;
}

public function getHeadingTextColour()
{
return $this->GetLocalInfoXML()->css->headingTextColour;
$headingTextColour = (string) $this->GetLocalInfoXML()->css->headingTextColour;

return $headingTextColour;
}

/**
Expand All @@ -372,9 +403,8 @@ public function getHeadingTextColour()
*/
public function IsOptionalFeatureSet($featureName)
{
$localInfo = $this->GetLocalInfoXML();
$feature = $localInfo->optional_features->$featureName;
if ((string) $feature == "true") {
$feature = (string) $this->GetLocalInfoXML()->optional_features->$featureName;
if ($feature == "true") {
return true;
} else {
return false;
Expand All @@ -388,9 +418,8 @@ public function IsOptionalFeatureSet($featureName)
*/
public function GetPortalURL()
{
$localInfo = $this->GetLocalInfoXML();
$url = $localInfo->web_portal_url;
return strval($url);
$portalUrl = (string) $this->GetLocalInfoXML()->web_portal_url;
return $portalUrl;
}
/**
* How Personal Data is restricted;
Expand All @@ -404,9 +433,8 @@ public function isRestrictPDByRole($forceStrict = false)
if ($forceStrict === true)
return true;

$localInfo = $this->GetLocalInfoXML();
$value = $localInfo->restrict_personal_data;
if ((string) $value == "true") {
$value = (string) $this->GetLocalInfoXML()->restrict_personal_data;
if ($value == "true") {
return true;
} else {
return false;
Expand All @@ -417,9 +445,9 @@ public function isRestrictPDByRole($forceStrict = false)
*/
public function getPiUrl()
{
$localInfo = $this->GetLocalInfoXML();
$url = $localInfo->pi_url;
return strval($url);
$piUrl = (string) $this->GetLocalInfoXML()->pi_url;

return $piUrl;
}

/**
Expand All @@ -428,9 +456,9 @@ public function getPiUrl()
*/
public function getServerBaseUrl()
{
$localInfo = $this->GetLocalInfoXML();
$url = $localInfo->server_base_url;
return strval($url);
$serverBaseUrl = (string) $this->GetLocalInfoXML()->server_base_url;

return $serverBaseUrl;
}

/**
Expand All @@ -439,32 +467,32 @@ public function getServerBaseUrl()
*/
public function getWriteApiDocsUrl()
{
$localInfo = $this->GetLocalInfoXML();
$url = $localInfo->write_api_user_docs_url;
return strval($url);
$writeApiDocsUrl = (string) $this->GetLocalInfoXML()->write_api_user_docs_url;

return $writeApiDocsUrl;
}

public function getDefaultScopeName()
{
//$scopeName = $this->GetLocalInfoXML()->local_info->default_scope->name;
$scopeName = $this->GetLocalInfoXML()->default_scope->name;
//$scopeName = (string) $this->GetLocalInfoXML()->local_info->default_scope->name;
$scopeName = (string) $this->GetLocalInfoXML()->default_scope->name;

if (empty($scopeName)) {
$scopeName = '';
}

return strval($scopeName);
return $scopeName;
}

public function getDefaultScopeMatch()
{
$scopeMatch = $this->GetLocalInfoXML()->default_scope_match;
$scopeMatch = (string) $this->GetLocalInfoXML()->default_scope_match;

if (empty($scopeMatch)) {
$scopeMatch = 'all';
}

return strval($scopeMatch);
return $scopeMatch;
}

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

$numScopesRequired = $this->GetLocalInfoXML()->minimum_scopes->$entityType;
$numScopesRequired = (int) $this->GetLocalInfoXML()->minimum_scopes->$entityType;

if (empty($numScopesRequired)) {
$numScopesRequired = 0;
}

return intval($numScopesRequired);
return $numScopesRequired;
}

public function getDefaultFilterByScope()
Expand All @@ -496,7 +524,7 @@ public function getDefaultFilterByScope()

public function getShowMapOnStartPage()
{
$showMapString = $this->GetLocalInfoXML()->show_map_on_start_page;
$showMapString = (string) $this->GetLocalInfoXML()->show_map_on_start_page;

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

public function getExtensionsLimit()
{
return $this->GetLocalInfoXML()->extensions->max;
$extensionsLimit = (int) $this->GetLocalInfoXML()->extensions->max;

return $extensionsLimit;
}


public function getSendEmails()
{
$sendEmailString = $this->GetLocalInfoXML()->send_email;
$sendEmailString = (string) $this->GetLocalInfoXML()->send_email;
if (empty($sendEmailString)) {
$sendEmail = false;
} elseif (strtolower($sendEmailString) == 'true') {
Expand All @@ -538,21 +568,21 @@ public function getAPIAllAuthRealms()

public function getPageBanner()
{
$bannerText = $this->GetLocalInfoXML()->page_banner;
$bannerText = (string) $this->GetLocalInfoXML()->page_banner;

return $bannerText;
}

public function getEmailFrom()
{
$emailFrom = $this->GetLocalInfoXML()->email_from;
$emailFrom = (string) $this->GetLocalInfoXML()->email_from;

return $emailFrom;
}

public function getEmailTo()
{
$emailTo = $this->GetlocalInfoXML()->email_to;
$emailTo = (string) $this->GetlocalInfoXML()->email_to;

return $emailTo;
}
Expand Down