Skip to content

Commit

Permalink
Merge pull request #8 from beatrycze-volk/implement-subject
Browse files Browse the repository at this point in the history
Implement functions in Subject class and its child element classes
  • Loading branch information
beatrycze-volk authored Apr 12, 2024
2 parents 01034c9 + e9a5fcc commit 87ae6eb
Show file tree
Hide file tree
Showing 10 changed files with 429 additions and 263 deletions.
31 changes: 29 additions & 2 deletions src/Mods/Element/Common/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(\SimpleXMLElement $xml)
}

/**
* Get the text value of element
* Get the text value of element.
*
* @access public
*
Expand All @@ -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
{
Expand All @@ -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;
}
}
7 changes: 1 addition & 6 deletions src/Mods/Element/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down
7 changes: 1 addition & 6 deletions src/Mods/Element/Specific/Part/Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down
Loading

0 comments on commit 87ae6eb

Please sign in to comment.