Skip to content

Commit a3cef6e

Browse files
committed
Reduce duplicated code.
1 parent eeebb28 commit a3cef6e

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/Exporter/Gv.php

+24-18
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,10 @@ public function export(NodeInterface $node): string
4848
}
4949

5050
if (\is_array($attribute)) {
51-
$attributesText = \array_map(
52-
static function ($key, $value) {
53-
return \sprintf('%s="%s"', $key, $value);
54-
},
55-
\array_keys($attribute),
56-
$attribute
57-
);
58-
5951
$attributes .= \sprintf(
6052
' %s %s' . "\n",
6153
$key,
62-
'[' . \implode(' ', $attributesText) . ']'
54+
$this->attributesArrayToText($attribute)
6355
);
6456

6557
continue;
@@ -131,6 +123,28 @@ public function setGraphAttributes(array $attributes): Gv
131123
return $this;
132124
}
133125

126+
/**
127+
* Converts an attributes array to string.
128+
*
129+
* @param array $attributes
130+
* The attributes.
131+
*
132+
* @return string
133+
* The attributes as string.
134+
*/
135+
protected function attributesArrayToText(array $attributes): string
136+
{
137+
$attributesText = \array_map(
138+
static function ($key, $value) {
139+
return \sprintf('%s="%s"', $key, $value);
140+
},
141+
\array_keys($attributes),
142+
$attributes
143+
);
144+
145+
return '[' . \implode(' ', $attributesText) . ']';
146+
}
147+
134148
/**
135149
* Recursively find all the edges in a tree.
136150
*
@@ -213,14 +227,6 @@ protected function getNodeAttributes(NodeInterface $node): string
213227
}
214228
}
215229

216-
$attributesText = \array_map(
217-
static function ($key, $value) {
218-
return \sprintf('%s="%s"', $key, $value);
219-
},
220-
\array_keys($attributes),
221-
$attributes
222-
);
223-
224-
return '[' . \implode(' ', $attributesText) . ']';
230+
return $this->attributesArrayToText($attributes);
225231
}
226232
}

0 commit comments

Comments
 (0)