Skip to content

Commit

Permalink
Make SVGNodeContainer methods chainable (fix #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
meyfa committed Nov 5, 2016
1 parent 1137e78 commit 98aebf0
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/Nodes/SVGNodeContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@ public function __construct($name)
*
* @param SVGNode $node The node to add to this container's children.
*
* @return bool Whether the action was valid and the child list changed.
* @return $this This node instance, for call chaining.
*/
public function addChild(SVGNode $node)
{
if ($node === $this) {
return false;
}

if ($node->parent === $this) {
return false;
if ($node === $this || $node->parent === $this) {
return $this;
}

if (isset($node->parent)) {
Expand All @@ -47,7 +43,7 @@ public function addChild(SVGNode $node)
$this->children[] = $node;
$node->parent = $this;

return true;
return $this;
}

/**
Expand All @@ -56,21 +52,21 @@ public function addChild(SVGNode $node)
*
* @param SVGNode|int $nodeOrIndex The node (or respective index) to remove.
*
* @return bool Whether the action was valid and the child list changed.
* @return $this This node instance, for call chaining.
*/
public function removeChild($nodeOrIndex)
{
$index = $this->resolveChildIndex($nodeOrIndex);
if ($index === false) {
return false;
return $this;
}

$node = $this->children[$index];
$node->parent = null;

array_splice($this->children, $index, 1);

return true;
return $this;
}

/**
Expand Down

0 comments on commit 98aebf0

Please sign in to comment.