File tree 8 files changed +36
-9
lines changed
spec/drupol/phptree/tests/Exporter
8 files changed +36
-9
lines changed Original file line number Diff line number Diff line change 6
6
7
7
use drupol \phptree \Node \ValueNode ;
8
8
use drupol \phptree \tests \Exporter \ValueGraph ;
9
+ use Fhaculty \Graph \Vertex ;
9
10
use PhpSpec \ObjectBehavior ;
10
11
11
12
class ValueGraphSpec extends ObjectBehavior
@@ -21,6 +22,13 @@ public function it_can_be_extended()
21
22
22
23
$ this
23
24
->export ($ tree )
24
- ->shouldReturnAnInstanceOf (\Fhaculty \Graph \Graph::class);
25
+ ->getVertex ('root ' )
26
+ ->shouldReturnAnInstanceOf (Vertex::class);
27
+
28
+ $ this
29
+ ->export ($ tree )
30
+ ->getVertex ('root ' )
31
+ ->getAttribute ('value ' )
32
+ ->shouldReturn ('root ' );
25
33
}
26
34
}
Original file line number Diff line number Diff line change 17
17
class Graph implements ExporterInterface
18
18
{
19
19
/**
20
+ * The graph.
21
+ *
20
22
* @var \Fhaculty\Graph\Graph
21
23
*/
22
24
private $ graph ;
23
25
24
26
/**
27
+ * The traverser.
28
+ *
25
29
* @var \drupol\phptree\Traverser\TraverserInterface
26
30
*/
27
31
private $ traverser ;
Original file line number Diff line number Diff line change 10
10
interface KeyValueNodeInterface extends ValueNodeInterface
11
11
{
12
12
/**
13
- * Get the node key.
13
+ * Get the key property .
14
14
*
15
15
* @return string|mixed|int|null
16
- * The key value .
16
+ * The key property .
17
17
*/
18
18
public function getKey ();
19
19
}
Original file line number Diff line number Diff line change 7
7
use drupol \phptree \Traverser \BreadthFirst ;
8
8
9
9
/**
10
- * Class NaryNode
10
+ * Class NaryNode.
11
11
*/
12
12
class NaryNode extends Node
13
13
{
14
14
/**
15
+ * The capacity of a node, the maximum children a node can have.
16
+ *
15
17
* @var int
16
18
*/
17
19
private $ capacity ;
@@ -20,7 +22,9 @@ class NaryNode extends Node
20
22
* NaryNode constructor.
21
23
*
22
24
* @param int $capacity
25
+ * The maximum children a node can have.
23
26
* @param \drupol\phptree\Node\NodeInterface|null $parent
27
+ * The parent.
24
28
*/
25
29
public function __construct (int $ capacity = 0 , NodeInterface $ parent = null )
26
30
{
Original file line number Diff line number Diff line change 5
5
namespace drupol \phptree \Node ;
6
6
7
7
/**
8
- * Class NaryNode
8
+ * Interface NaryNodeInterface
9
9
*/
10
10
interface NaryNodeInterface
11
11
{
12
12
/**
13
- * {@inheritdoc}
13
+ * Get the node capacity.
14
+ *
15
+ * @return int
16
+ * The node capacity.
14
17
*/
15
18
public function capacity (): int ;
16
19
}
Original file line number Diff line number Diff line change 10
10
class ValueNode extends NaryNode implements ValueNodeInterface
11
11
{
12
12
/**
13
+ * The value property.
14
+ *
13
15
* @var string|mixed|null
14
16
*/
15
17
private $ value ;
Original file line number Diff line number Diff line change 10
10
interface ValueNodeInterface extends NodeInterface
11
11
{
12
12
/**
13
- * Get the node value.
13
+ * Get the value property .
14
14
*
15
15
* @return string|mixed|null
16
- * The node value.
16
+ * The value property .
17
17
*/
18
18
public function getValue ();
19
19
}
Original file line number Diff line number Diff line change @@ -18,7 +18,13 @@ class ValueGraph extends Graph
18
18
*/
19
19
protected function createVertex (NodeInterface $ node ): Vertex
20
20
{
21
- return parent ::createVertex ($ node );
21
+ $ vertex = parent ::createVertex ($ node );
22
+
23
+ if (\method_exists ($ node , 'getValue ' )) {
24
+ $ vertex ->setAttribute ('value ' , $ node ->getValue ());
25
+ }
26
+
27
+ return $ vertex ;
22
28
}
23
29
24
30
/**
You can’t perform that action at this time.
0 commit comments