File tree 3 files changed +44
-3
lines changed
3 files changed +44
-3
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,25 @@ public function it_can_add(NodeInterface $node)
21
21
->shouldReturn ($ this );
22
22
}
23
23
24
+ public function it_can_remove ()
25
+ {
26
+ $ node1 = new Node ();
27
+ $ node2 = new Node ();
28
+
29
+ $ this
30
+ ->add ($ node1 , $ node2 );
31
+
32
+ $ this
33
+ ->remove ($ node2 );
34
+
35
+ $ this ->children ()[0 ]->shouldReturn ($ node1 );
36
+
37
+ $ this
38
+ ->remove ($ node1 );
39
+
40
+ $ this ->children ()->shouldReturn ([]);
41
+ }
42
+
24
43
public function it_can_get_the_size ()
25
44
{
26
45
$ nodes = [];
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ public function __construct(NodeInterface $parent = null)
30
30
/**
31
31
* {@inheritdoc}
32
32
*/
33
- public function add (NodeInterface ...$ nodes )
33
+ public function add (NodeInterface ...$ nodes ): NodeInterface
34
34
{
35
35
foreach ($ nodes as $ node ) {
36
36
$ this ->storage ['children ' ][] = $ node ->setParent ($ this );
@@ -39,6 +39,21 @@ public function add(NodeInterface ...$nodes)
39
39
return $ this ;
40
40
}
41
41
42
+ /**
43
+ * {@inheritdoc}
44
+ */
45
+ public function remove (NodeInterface ...$ nodes ): NodeInterface
46
+ {
47
+ $ this ->storage ['children ' ] = \array_filter (
48
+ $ this ->storage ['children ' ],
49
+ function ($ child ) use ($ nodes ) {
50
+ return !\in_array ($ child , $ nodes , true );
51
+ }
52
+ );
53
+
54
+ return $ this ;
55
+ }
56
+
42
57
/**
43
58
* {@inheritdoc}
44
59
*/
Original file line number Diff line number Diff line change @@ -24,9 +24,16 @@ public function setParent(NodeInterface $node): NodeInterface;
24
24
/**
25
25
* @param \drupol\phptree\Node\NodeInterface ...$node
26
26
*
27
- * @return mixed
27
+ * @return \drupol\phptree\Node\NodeInterface
28
+ */
29
+ public function add (NodeInterface ...$ node ): NodeInterface ;
30
+
31
+ /**
32
+ * @param \drupol\phptree\Node\NodeInterface ...$node
33
+ *
34
+ * @return \drupol\phptree\Node\NodeInterface
28
35
*/
29
- public function add (NodeInterface ...$ node );
36
+ public function remove (NodeInterface ...$ node ): NodeInterface ;
30
37
31
38
/**
32
39
* @return NodeInterface[]
You can’t perform that action at this time.
0 commit comments