Skip to content

Commit 981aeb5

Browse files
ENGCOM-1015: [Forwardport] Improve array output format for etc.php and config.php #14241
- Merge Pull Request #14241 from mastiuhin-olexandr/magento2:2.3-develop-PR-port-14042 - Merged commits: 1. 3cc4498
2 parents a1f3e7f + 3cc4498 commit 981aeb5

File tree

2 files changed

+74
-85
lines changed

2 files changed

+74
-85
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
class PhpFormatter implements FormatterInterface
1313
{
1414
/**
15-
* 2 space indentation for array formatting.
15+
* 4 space indentation for array formatting.
1616
*/
17-
const INDENT = ' ';
17+
const INDENT = ' ';
1818

1919
/**
2020
* Format deployment configuration.
@@ -39,7 +39,7 @@ public function format($data, array $comments = [])
3939
* @param string $prefix
4040
* @return string
4141
*/
42-
private function formatData($data, $comments = [], $prefix = ' ')
42+
private function formatData($data, $comments = [], $prefix = ' ')
4343
{
4444
$elements = [];
4545

@@ -56,13 +56,12 @@ private function formatData($data, $comments = [], $prefix = ' ')
5656
$elements[] = $prefix . " */";
5757
}
5858

59-
$elements[] = $prefix . $this->varExportShort($key) . ' => ' .
60-
(!is_array($value) ? $this->varExportShort($value) . ',' : '');
61-
6259
if (is_array($value)) {
63-
$elements[] = $prefix . '[';
64-
$elements[] = $this->formatData($value, [], ' ' . $prefix);
60+
$elements[] = $prefix . $this->varExportShort($key) . ' => [';
61+
$elements[] = $this->formatData($value, [], ' ' . $prefix);
6562
$elements[] = $prefix . '],';
63+
} else {
64+
$elements[] = $prefix . $this->varExportShort($key) . ' => ' . $this->varExportShort($value) . ',';
6665
}
6766
}
6867
return implode("\n", $elements);

lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/Writer/PhpFormatterTest.php

Lines changed: 67 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -56,101 +56,91 @@ public function formatWithCommentDataProvider()
5656
$expectedResult1 = <<<TEXT
5757
<?php
5858
return [
59-
'ns1' =>
60-
[
61-
's1' =>
62-
[
63-
0 => 's11',
64-
1 => 's12',
59+
'ns1' => [
60+
's1' => [
61+
0 => 's11',
62+
1 => 's12',
63+
],
64+
's2' => [
65+
0 => 's21',
66+
1 => 's22',
67+
],
6568
],
66-
's2' =>
67-
[
68-
0 => 's21',
69-
1 => 's22',
70-
],
71-
],
72-
/**
73-
* For the section: ns2
74-
* comment for namespace 2
75-
*/
76-
'ns2' =>
77-
[
78-
's1' =>
79-
[
80-
0 => 's11',
69+
/**
70+
* For the section: ns2
71+
* comment for namespace 2
72+
*/
73+
'ns2' => [
74+
's1' => [
75+
0 => 's11',
76+
],
8177
],
82-
],
83-
'ns3' => 'just text',
84-
'ns4' => 'just text',
78+
'ns3' => 'just text',
79+
'ns4' => 'just text',
8580
];
8681
8782
TEXT;
8883
$expectedResult2 = <<<TEXT
8984
<?php
9085
return [
91-
/**
92-
* For the section: ns1
93-
* comment for' namespace 1
94-
*/
95-
'ns1' =>
96-
[
97-
's1' =>
98-
[
99-
0 => 's11',
100-
1 => 's12',
101-
],
102-
's2' =>
103-
[
104-
0 => 's21',
105-
1 => 's22',
86+
/**
87+
* For the section: ns1
88+
* comment for' namespace 1
89+
*/
90+
'ns1' => [
91+
's1' => [
92+
0 => 's11',
93+
1 => 's12',
94+
],
95+
's2' => [
96+
0 => 's21',
97+
1 => 's22',
98+
],
10699
],
107-
],
108-
/**
109-
* For the section: ns2
110-
* comment for namespace 2.
111-
* Next comment for' namespace 2
112-
*/
113-
'ns2' =>
114-
[
115-
's1' =>
116-
[
117-
0 => 's11',
100+
/**
101+
* For the section: ns2
102+
* comment for namespace 2.
103+
* Next comment for' namespace 2
104+
*/
105+
'ns2' => [
106+
's1' => [
107+
0 => 's11',
108+
],
118109
],
119-
],
120-
/**
121-
* For the section: ns3
122-
* comment for" namespace 3
123-
*/
124-
'ns3' => 'just text',
125-
/**
126-
* For the section: ns4
127-
* comment for namespace 4
128-
*/
129-
'ns4' => 'just text',
110+
/**
111+
* For the section: ns3
112+
* comment for" namespace 3
113+
*/
114+
'ns3' => 'just text',
115+
/**
116+
* For the section: ns4
117+
* comment for namespace 4
118+
*/
119+
'ns4' => 'just text',
130120
];
131121
132122
TEXT;
133123

134124
$expectedResult3 = <<<TEXT
135125
<?php
136126
return [
137-
'ns1' => [
138-
's1' => [
139-
's11',
140-
's12'
127+
'ns1' => [
128+
's1' => [
129+
's11',
130+
's12'
131+
],
132+
's2' => [
133+
's21',
134+
's22'
135+
]
136+
],
137+
'ns2' => [
138+
's1' => [
139+
's11'
140+
]
141141
],
142-
's2' => [
143-
's21',
144-
's22'
145-
]
146-
],
147-
'ns2' => [
148-
's1' => [
149-
's11'
150-
]
151-
],
152-
'ns3' => 'just text',
153-
'ns4' => 'just text'
142+
'ns3' => 'just text',
143+
'ns4' => 'just text'
154144
];
155145
156146
TEXT;

0 commit comments

Comments
 (0)