Skip to content

Commit 9dfd69d

Browse files
committed
Add a KeyValueGraph test class for displaying graphs with a key and a value.
1 parent d1658da commit 9dfd69d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/src/Exporter/KeyValueGraph.php

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace drupol\phptree\tests\Exporter;
6+
7+
use drupol\phptree\Node\NodeInterface;
8+
use Fhaculty\Graph\Vertex;
9+
10+
/**
11+
* Class KeyValueGraph
12+
*/
13+
class KeyValueGraph extends ValueGraph
14+
{
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
protected function createVertex(NodeInterface $node): Vertex
19+
{
20+
$vertex = parent::createVertex($node);
21+
22+
if (\method_exists($node, 'getValue') && \method_exists($node, 'getKey')) {
23+
$vertex->setAttribute('graphviz.label', $node->getValue());
24+
}
25+
26+
return $vertex;
27+
}
28+
29+
/**
30+
* {@inheritdoc}
31+
*/
32+
protected function createVertexId(NodeInterface $node)
33+
{
34+
if (\method_exists($node, 'getValue') && \method_exists($node, 'getKey')) {
35+
return $node->getKey() . $node->getValue();
36+
}
37+
38+
return \sha1((string) parent::createVertexId($node));
39+
}
40+
}

0 commit comments

Comments
 (0)