Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a998d4b

Browse files
committed
[Yaml] Extract duplicate code to private function
1 parent b02a689 commit a998d4b

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,7 @@ public static function dump(mixed $value, int $flags = 0): string
123123
}
124124

125125
if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \stdClass || $value instanceof \ArrayObject)) {
126-
$output = [];
127-
128-
foreach ($value as $key => $val) {
129-
$output[] = sprintf('%s: %s', self::dump($key, $flags), self::dump($val, $flags));
130-
}
131-
132-
return sprintf('{ %s }', implode(', ', $output));
126+
return self::dumpHashArray($value, $flags);
133127
}
134128

135129
if (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $flags) {
@@ -232,7 +226,17 @@ private static function dumpArray(array $value, int $flags): string
232226
return sprintf('[%s]', implode(', ', $output));
233227
}
234228

235-
// hash
229+
return self::dumpHashArray($value, $flags);
230+
}
231+
232+
/**
233+
* Dumps hash array to a YAML string.
234+
*
235+
* @param array|\ArrayObject|\stdClass $value The hash array to dump
236+
* @param int $flags A bit field of Yaml::DUMP_* constants to customize the dumped YAML string
237+
*/
238+
private static function dumpHashArray(array|\ArrayObject|\stdClass $value, int $flags): string
239+
{
236240
$output = [];
237241
foreach ($value as $key => $val) {
238242
$output[] = sprintf('%s: %s', self::dump($key, $flags), self::dump($val, $flags));

0 commit comments

Comments
 (0)