@@ -32,11 +32,11 @@ class Gv implements ExporterInterface
32
32
*/
33
33
public function export (NodeInterface $ node ): string
34
34
{
35
- $ attributes = '' ;
35
+ $ attributes = [] ;
36
36
foreach ($ this ->attributes as $ key => $ attribute ) {
37
37
if (\is_string ($ attribute )) {
38
- $ attributes . = \sprintf (
39
- ' %s = %s ' . "\n" ,
38
+ $ attributes[] = \sprintf (
39
+ ' %s = %s ' ,
40
40
$ key ,
41
41
$ attribute
42
42
);
@@ -45,8 +45,8 @@ public function export(NodeInterface $node): string
45
45
}
46
46
47
47
if (\is_array ($ attribute )) {
48
- $ attributes . = \sprintf (
49
- ' %s %s ' . "\n" ,
48
+ $ attributes[] = \sprintf (
49
+ ' %s %s ' ,
50
50
$ key ,
51
51
$ this ->attributesArrayToText ($ attribute )
52
52
);
@@ -55,26 +55,30 @@ public function export(NodeInterface $node): string
55
55
}
56
56
}
57
57
58
- $ nodes = '' ;
58
+ $ nodes = [] ;
59
59
foreach ($ node ->all () as $ child ) {
60
- $ nodes . = \sprintf (
61
- ' "%s" %s ' . "\n" ,
60
+ $ nodes[] = \sprintf (
61
+ ' "%s" %s ' ,
62
62
$ this ->getHash ($ child ),
63
63
$ this ->getNodeAttributes ($ child )
64
64
);
65
65
}
66
66
67
- $ edges = '' ;
67
+ $ edges = [] ;
68
68
foreach ($ this ->findEdges ($ node ) as $ parent => $ child ) {
69
- $ edges . = \sprintf (
70
- ' "%s" %s "%s"; ' . "\n" ,
69
+ $ edges[] = \sprintf (
70
+ ' "%s" %s "%s"; ' ,
71
71
$ this ->getHash ($ parent ),
72
72
true === $ this ->getDirected () ? '-> ' : '-- ' ,
73
73
$ this ->getHash ($ child )
74
74
);
75
75
}
76
76
77
- return $ this ->getGv ($ attributes , $ nodes , $ edges );
77
+ return $ this ->getGv (
78
+ implode (PHP_EOL , $ attributes ),
79
+ implode (PHP_EOL , $ nodes ),
80
+ implode (PHP_EOL , $ edges )
81
+ );
78
82
}
79
83
80
84
/**
@@ -179,9 +183,13 @@ protected function getGv(string $attributes = '', string $nodes = '', string $ed
179
183
180
184
return <<<EOF
181
185
{$ graphType } PHPTreeGraph {
182
-
186
+ // The graph attributes.
183
187
{$ attributes }
188
+
189
+ // The graph nodes.
184
190
{$ nodes }
191
+
192
+ // The graph edges.
185
193
{$ edges }
186
194
}
187
195
EOF ;
0 commit comments