Skip to content

Commit

Permalink
Allow for null value for attributes in Dom\Child
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksagona committed Jun 17, 2024
1 parent e32509b commit ac3d6c5
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/Child.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,26 +347,26 @@ public function isCData(): bool
/**
* Set an attribute for the child element object
*
* @param string $a
* @param string $v
* @param string $name
* @param ?string $value
* @return Child
*/
public function setAttribute(string $a, string $v): Child
public function setAttribute(string $name, ?string $value = null): Child
{
$this->attributes[$a] = $v;
$this->attributes[$name] = $value;
return $this;
}

/**
* Set an attribute or attributes for the child element object
*
* @param array $a
* @param array $attributes
* @return Child
*/
public function setAttributes(array $a): Child
public function setAttributes(array $attributes): Child
{
foreach ($a as $name => $value) {
$this->attributes[$name] = $value;
foreach ($attributes as $name => $value) {
$this->setAttribute($name, $value);
}
return $this;
}
Expand All @@ -379,7 +379,7 @@ public function setAttributes(array $a): Child
*/
public function hasAttribute(string $name): bool
{
return (isset($this->attributes[$name]));
return isset($this->attributes[$name]);
}

/**
Expand All @@ -396,9 +396,9 @@ public function hasAttributes(): bool
* Get the attribute of the child object
*
* @param string $name
* @return string|null
* @return ?string
*/
public function getAttribute(string $name): string|null
public function getAttribute(string $name): ?string
{
return $this->attributes[$name] ?? null;
}
Expand All @@ -416,13 +416,13 @@ public function getAttributes(): array
/**
* Remove an attribute from the child element object
*
* @param string $a
* @param string $name
* @return Child
*/
public function removeAttribute(string $a): Child
public function removeAttribute(string $name): Child
{
if (isset($this->attributes[$a])) {
unset($this->attributes[$a]);
if (isset($this->attributes[$name])) {
unset($this->attributes[$name]);
}
return $this;
}
Expand Down Expand Up @@ -493,7 +493,7 @@ public function render(int $depth = 0, ?string $indent = null, bool $inner = fal
// Initialize the node.
if ($this->nodeName == '#text') {
$this->output .= ((!$this->preserveWhiteSpace) ?
'' : "{$indent}{$this->indent}") . $this->nodeValue . ((!$this->preserveWhiteSpace) ? '' : "\n");
'' : "{$indent}{$this->indent}") . $this->nodeValue . ((!$this->preserveWhiteSpace) ? '' : "\n");
} else {
if (!$inner) {
$this->output .= ((!$this->preserveWhiteSpace) ?
Expand Down

0 comments on commit ac3d6c5

Please sign in to comment.