Skip to content

Commit f2e0875

Browse files
committed
Update documentation and code coverage.
1 parent c24713c commit f2e0875

File tree

8 files changed

+36
-9
lines changed

8 files changed

+36
-9
lines changed

spec/drupol/phptree/tests/Exporter/ValueGraphSpec.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use drupol\phptree\Node\ValueNode;
88
use drupol\phptree\tests\Exporter\ValueGraph;
9+
use Fhaculty\Graph\Vertex;
910
use PhpSpec\ObjectBehavior;
1011

1112
class ValueGraphSpec extends ObjectBehavior
@@ -21,6 +22,13 @@ public function it_can_be_extended()
2122

2223
$this
2324
->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');
2533
}
2634
}

src/Exporter/Graph.php

+4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
class Graph implements ExporterInterface
1818
{
1919
/**
20+
* The graph.
21+
*
2022
* @var \Fhaculty\Graph\Graph
2123
*/
2224
private $graph;
2325

2426
/**
27+
* The traverser.
28+
*
2529
* @var \drupol\phptree\Traverser\TraverserInterface
2630
*/
2731
private $traverser;

src/Node/KeyValueNodeInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
interface KeyValueNodeInterface extends ValueNodeInterface
1111
{
1212
/**
13-
* Get the node key.
13+
* Get the key property.
1414
*
1515
* @return string|mixed|int|null
16-
* The key value.
16+
* The key property.
1717
*/
1818
public function getKey();
1919
}

src/Node/NaryNode.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
use drupol\phptree\Traverser\BreadthFirst;
88

99
/**
10-
* Class NaryNode
10+
* Class NaryNode.
1111
*/
1212
class NaryNode extends Node
1313
{
1414
/**
15+
* The capacity of a node, the maximum children a node can have.
16+
*
1517
* @var int
1618
*/
1719
private $capacity;
@@ -20,7 +22,9 @@ class NaryNode extends Node
2022
* NaryNode constructor.
2123
*
2224
* @param int $capacity
25+
* The maximum children a node can have.
2326
* @param \drupol\phptree\Node\NodeInterface|null $parent
27+
* The parent.
2428
*/
2529
public function __construct(int $capacity = 0, NodeInterface $parent = null)
2630
{

src/Node/NaryNodeInterface.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
namespace drupol\phptree\Node;
66

77
/**
8-
* Class NaryNode
8+
* Interface NaryNodeInterface
99
*/
1010
interface NaryNodeInterface
1111
{
1212
/**
13-
* {@inheritdoc}
13+
* Get the node capacity.
14+
*
15+
* @return int
16+
* The node capacity.
1417
*/
1518
public function capacity(): int;
1619
}

src/Node/ValueNode.php

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
class ValueNode extends NaryNode implements ValueNodeInterface
1111
{
1212
/**
13+
* The value property.
14+
*
1315
* @var string|mixed|null
1416
*/
1517
private $value;

src/Node/ValueNodeInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
interface ValueNodeInterface extends NodeInterface
1111
{
1212
/**
13-
* Get the node value.
13+
* Get the value property.
1414
*
1515
* @return string|mixed|null
16-
* The node value.
16+
* The value property.
1717
*/
1818
public function getValue();
1919
}

tests/src/Exporter/ValueGraph.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ class ValueGraph extends Graph
1818
*/
1919
protected function createVertex(NodeInterface $node): Vertex
2020
{
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;
2228
}
2329

2430
/**

0 commit comments

Comments
 (0)