9
9
use loophp \phptree \Node \AttributeNodeInterface ;
10
10
use loophp \phptree \Node \NodeInterface ;
11
11
12
- /**
13
- * Class Graph.
14
- */
15
12
final class Graph implements ExporterInterface
16
13
{
17
- /**
18
- * The graph.
19
- *
20
- * @var \Fhaculty\Graph\Graph
21
- */
22
- private $ graph ;
23
-
24
- /**
25
- * {@inheritdoc}
26
- */
27
14
public function export (NodeInterface $ node ): OriginalGraph
28
15
{
29
- $ this -> graph = new OriginalGraph ();
16
+ $ graph = new OriginalGraph ();
30
17
31
18
foreach ($ node ->all () as $ node_visited ) {
32
- $ vertexFrom = $ this ->createVertex ($ node_visited );
19
+ $ vertexFrom = $ this ->createVertex ($ node_visited, $ graph );
33
20
34
21
foreach ($ node_visited ->children () as $ child ) {
35
- $ vertexTo = $ this ->createVertex ($ child );
22
+ $ vertexTo = $ this ->createVertex ($ child, $ graph );
36
23
$ vertexFrom ->createEdgeTo ($ vertexTo );
37
24
}
38
25
}
39
26
40
- return $ this -> getGraph () ;
27
+ return $ graph ;
41
28
}
42
29
43
30
/**
@@ -49,13 +36,13 @@ public function export(NodeInterface $node): OriginalGraph
49
36
* @return Vertex
50
37
* A vertex
51
38
*/
52
- private function createVertex (NodeInterface $ node ): Vertex
39
+ private function createVertex (NodeInterface $ node, OriginalGraph $ graph ): Vertex
53
40
{
54
41
/** @var int $vertexId */
55
42
$ vertexId = $ this ->createVertexId ($ node );
56
43
57
- if (!$ this -> getGraph () ->hasVertex ($ vertexId )) {
58
- $ vertex = $ this -> getGraph () ->createVertex ($ vertexId );
44
+ if (!$ graph ->hasVertex ($ vertexId )) {
45
+ $ vertex = $ graph ->createVertex ($ vertexId );
59
46
60
47
$ vertex ->setAttribute (
61
48
'graphviz.label ' ,
@@ -69,25 +56,11 @@ private function createVertex(NodeInterface $node): Vertex
69
56
}
70
57
}
71
58
72
- return $ this -> getGraph () ->getVertex ($ vertexId );
59
+ return $ graph ->getVertex ($ vertexId );
73
60
}
74
61
75
- /**
76
- * Create a vertex ID.
77
- *
78
- * @param NodeInterface $node
79
- * The node
80
- *
81
- * @return string
82
- * A vertex ID
83
- */
84
62
private function createVertexId (NodeInterface $ node ): string
85
63
{
86
64
return sha1 (spl_object_hash ($ node ));
87
65
}
88
-
89
- private function getGraph (): OriginalGraph
90
- {
91
- return $ this ->graph ;
92
- }
93
66
}
0 commit comments