Skip to content

Commit e66bea8

Browse files
committed
Fixes per ishakhsuvarov code review:
- const documenation - reverse condition for readability - better variable name - type and return hints
1 parent ed2886f commit e66bea8

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
*/
1212
class PhpFormatter implements FormatterInterface
1313
{
14+
/**
15+
* 2 space indentation for array formatting
16+
*/
1417
const INDENT = ' ';
1518

1619
/**
@@ -76,19 +79,20 @@ private function formatData($data, $comments = [], $prefix = ' ')
7679
* @param integer $depth
7780
* @return string
7881
*/
79-
private function varExportShort($var, $depth = 0)
82+
private function varExportShort($var, int $depth = 0): string
8083
{
81-
if (gettype($var) === 'array') {
82-
$indexed = array_keys($var) === range(0, count($var) - 1);
83-
$r = [];
84-
foreach ($var as $key => $value) {
85-
$r[] = str_repeat(self::INDENT, $depth)
86-
. ($indexed ? '' : $this->varExportShort($key) . ' => ')
87-
. $this->varExportShort($value, $depth + 1);
88-
}
89-
return sprintf("[\n%s\n%s]", implode(",\n", $r), str_repeat(self::INDENT, $depth - 1));
84+
if (!is_array($var)) {
85+
return var_export($var, true);
86+
}
87+
88+
$indexed = array_keys($var) === range(0, count($var) - 1);
89+
$expanded = [];
90+
foreach ($var as $key => $value) {
91+
$expanded[] = str_repeat(self::INDENT, $depth)
92+
. ($indexed ? '' : $this->varExportShort($key) . ' => ')
93+
. $this->varExportShort($value, $depth + 1);
9094
}
9195

92-
return var_export($var, true);
96+
return sprintf("[\n%s\n%s]", implode(",\n", $expanded), str_repeat(self::INDENT, $depth - 1));
9397
}
9498
}

0 commit comments

Comments
 (0)