Skip to content

Commit

Permalink
Fix setStyle/setAttribute unset behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
meyfa committed Dec 30, 2017
1 parent bc26135 commit 0747a98
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/Nodes/SVGNode.php
Expand Up @@ -75,15 +75,21 @@ public function getStyle($name)
}

/**
* Defines a style on this node.
* Defines a style on this node. A value of null or the empty string will
* unset the property.
*
* @param string $name The name of the style to set.
* @param string $value The new style value.
* @param string $name The name of the style to set.
* @param string|null $value The new style value.
*
* @return $this This node instance, for call chaining.
*/
public function setStyle($name, $value)
{
$value = (string) $value;
if (strlen($value) === 0) {
unset($this->styles[$name]);
return $this;
}
$this->styles[$name] = $value;
return $this;
}
Expand Down Expand Up @@ -145,16 +151,21 @@ public function getAttribute($name)
}

/**
* Defines an attribute on this node.
* Defines an attribute on this node. A value of null will unset the
* attribute. Note that the empty string is perfectly valid.
*
* @param string $name The name of the attribute to set.
* @param string $value The new attribute value.
* @param string $name The name of the attribute to set.
* @param string|null $value The new attribute value.
*
* @return $this This node instance, for call chaining.
*/
public function setAttribute($name, $value)
{
$this->attributes[$name] = $value;
if (!isset($value)) {
unset($this->attributes[$name]);
return $this;
}
$this->attributes[$name] = (string) $value;
return $this;
}

Expand Down

0 comments on commit 0747a98

Please sign in to comment.