diff --git a/src/Mods/Element/Common/BaseElement.php b/src/Mods/Element/Common/BaseElement.php index 54e2378..ece9ec7 100644 --- a/src/Mods/Element/Common/BaseElement.php +++ b/src/Mods/Element/Common/BaseElement.php @@ -41,7 +41,7 @@ public function __construct(\SimpleXMLElement $xml) } /** - * Get the text value of element + * Get the text value of element. * * @access public * @@ -53,7 +53,13 @@ public function getValue(): string } /** - * Get the string value of attribute + * Get the string value of attribute. + * + * @access public + * + * @param string $attribute name + * + * @return string */ protected function getStringAttribute($attribute): string { @@ -66,4 +72,25 @@ protected function getStringAttribute($attribute): string } return ''; } + + /** + * Get the int value of attribute. + * + * @access public + * + * @param string $attribute name + * + * @return int + */ + protected function getIntAttribute($attribute): int + { + if ($this->xml->attributes() != null) { + $value = $this->xml->attributes()->$attribute; + + if (!empty($value)) { + return (int) $value; + } + } + return 0; + } } \ No newline at end of file diff --git a/src/Mods/Element/Part.php b/src/Mods/Element/Part.php index 7cc328c..65d4382 100644 --- a/src/Mods/Element/Part.php +++ b/src/Mods/Element/Part.php @@ -90,12 +90,7 @@ public function getType(): string */ public function getOrder(): int { - $value = $this->xml->attributes()->order; - - if (!empty($value)) { - return (int) $value; - } - return 0; + return $this->getIntAttribute('order'); } /** diff --git a/src/Mods/Element/Specific/Part/Detail.php b/src/Mods/Element/Specific/Part/Detail.php index ed45f99..60dc489 100644 --- a/src/Mods/Element/Specific/Part/Detail.php +++ b/src/Mods/Element/Specific/Part/Detail.php @@ -76,12 +76,7 @@ public function getType(): string */ public function getLevel(): int { - $value = $this->xml->attributes()->level; - - if (!empty($value)) { - return (int) $value; - } - return 0; + return $this->getIntAttribute('level'); } /** diff --git a/src/Mods/Element/Specific/Subject/HierarchicalGeographic/LevelPeriodElement.php b/src/Mods/Element/Specific/Subject/HierarchicalGeographic/LevelPeriodElement.php index 8985ffe..25fed16 100644 --- a/src/Mods/Element/Specific/Subject/HierarchicalGeographic/LevelPeriodElement.php +++ b/src/Mods/Element/Specific/Subject/HierarchicalGeographic/LevelPeriodElement.php @@ -45,11 +45,11 @@ public function __construct(\SimpleXMLElement $xml) * * @access public * - * @return string + * @return int */ - public function getLevel(): string + public function getLevel(): int { - return $this->getStringAttribute('level'); + return $this->getIntAttribute('level'); } /**