From 36c4ed283c1189c6266bcdc7c8dceeaba6f7ece1 Mon Sep 17 00:00:00 2001 From: Nick Sagona Date: Fri, 27 Oct 2023 17:51:22 -0500 Subject: [PATCH] Add use of getAttributes() in the render method --- src/Child.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Child.php b/src/Child.php index 9db7625..64e42ac 100644 --- a/src/Child.php +++ b/src/Child.php @@ -382,6 +382,16 @@ public function hasAttribute(string $name): bool return (isset($this->attributes[$name])); } + /** + * Determine if the child object has attributes + * + * @return bool + */ + public function hasAttributes(): bool + { + return (count($this->attributes) > 0); + } + /** * Get the attribute of the child object * @@ -472,8 +482,9 @@ public function render(int $depth = 0, ?string $indent = null, bool $inner = fal } // Format child attributes, if applicable. - if (count($this->attributes) > 0) { - foreach ($this->attributes as $key => $value) { + if ($this->hasAttributes()) { + $attributes = $this->getAttributes(); + foreach ($attributes as $key => $value) { $attribAry[] = $key . "=\"" . $value . "\""; } $attribs = ' ' . implode(' ', $attribAry);