Internal: Refactor a small piece of code for better readability

This commit is contained in:
Molkobain
2019-12-10 13:06:29 +01:00
parent 46358b6e36
commit 464ee46631

View File

@@ -50,14 +50,18 @@ class Forms extends AbstractConfiguration
try try
{ {
// Parsing form id // Parsing form id
$sFormId = $oFormNode->getAttribute('id');
if ($oFormNode->getAttribute('id') === '') if ($oFormNode->getAttribute('id') === '')
{ {
throw new DOMFormatException('form tag must have an id attribute', null, null, $oFormNode); throw new DOMFormatException('form tag must have an id attribute', null, null, $oFormNode);
} }
// Parsing form object class // Parsing form object class
if ($oFormNode->GetUniqueElement('class')->GetText() !== null) if ($oFormNode->GetUniqueElement('class')->GetText() === null)
{ {
throw new DOMFormatException('Class tag must be defined', null, null, $oFormNode);
}
// Parsing class // Parsing class
$sFormClass = $oFormNode->GetUniqueElement('class')->GetText(); $sFormClass = $oFormNode->GetUniqueElement('class')->GetText();
@@ -142,18 +146,16 @@ class Forms extends AbstractConfiguration
/** @var \MFElement $oModeNode */ /** @var \MFElement $oModeNode */
foreach ($oFormNode->GetOptionalElement('modes')->GetNodes('mode') as $oModeNode) foreach ($oFormNode->GetOptionalElement('modes')->GetNodes('mode') as $oModeNode)
{ {
if ($oModeNode->getAttribute('id') !== '') $sModeId = $oModeNode->getAttribute('id');
{ if ($sModeId === '')
$aModes[] = $oModeNode->getAttribute('id');
}
else
{ {
throw new DOMFormatException('mode tag must have an id attribute', null, null, throw new DOMFormatException('mode tag must have an id attribute', null, null,
$oFormNode); $oFormNode);
} }
$aModes[] = $sModeId;
// If apply_stimulus mode, checking if stimuli are defined // If apply_stimulus mode, checking if stimuli are defined
if ($oModeNode->getAttribute('id') === 'apply_stimulus') if ($sModeId === 'apply_stimulus')
{ {
$oStimuliNode = $oModeNode->GetOptionalElement('stimuli'); $oStimuliNode = $oModeNode->GetOptionalElement('stimuli');
// if stimuli are defined, we overwrite the form that could have been set by the generic form // if stimuli are defined, we overwrite the form that could have been set by the generic form
@@ -185,7 +187,7 @@ class Forms extends AbstractConfiguration
// Parsing fields // Parsing fields
$aFields = array( $aFields = array(
'id' => $oFormNode->getAttribute('id'), 'id' => $sFormId,
'type' => null, 'type' => null,
'properties' => $aFormProperties, 'properties' => $aFormProperties,
'fields' => null, 'fields' => null,
@@ -307,11 +309,6 @@ class Forms extends AbstractConfiguration
} }
} }
} }
else
{
throw new DOMFormatException('Class tag must be defined', null, null, $oFormNode);
}
}
catch (DOMFormatException $e) catch (DOMFormatException $e)
{ {
throw new Exception('Could not create from [id="'.$oFormNode->getAttribute('id').'"] from XML because of a DOM problem : '.$e->getMessage()); throw new Exception('Could not create from [id="'.$oFormNode->getAttribute('id').'"] from XML because of a DOM problem : '.$e->getMessage());