Skip to content

Commit

Permalink
Adjust checking for element existence and getting the values
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrycze-volk committed Jun 17, 2024
1 parent a2335db commit f349da7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Mods/Element/Xml/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Element

/**
* @access protected
* @var array|false
* @var static[]|false|null
*/
protected array $values;

Expand Down Expand Up @@ -60,19 +60,21 @@ public function __construct(\SimpleXMLElement $xml, string $xpath)
*/
public function exists(): bool
{
return $this->values != false;
return $this->values != false && $this->values != null;
}

/**
* Get the array of values of the queried element.
*
* @access public
*
* @return array|false array if element exists, false otherwise
* @return array array with values if element exist, empty array otherwise
*/
// TODO: change return type after upgrade to PHP 8.x
public function getValues(): array
{
return $this->values;
if ($this->exists()) {
return $this->values;
}
return [];
}
}

0 comments on commit f349da7

Please sign in to comment.