Skip to content

Commit 4597c4f

Browse files
committed
Fix the config formatter scenarios with $comments to also use short array syntax
1 parent fe7e75f commit 4597c4f

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class PhpFormatter implements FormatterInterface
2323
public function format($data, array $comments = [])
2424
{
2525
if (!empty($comments) && is_array($data)) {
26-
return "<?php\nreturn array (\n" . $this->formatData($data, $comments) . "\n);\n";
26+
return "<?php\nreturn [\n" . $this->formatData($data, $comments) . "\n];\n";
2727
}
2828
return "<?php\nreturn " . $this->varExportShort($data, true) . ";\n";
2929
}
@@ -53,13 +53,13 @@ private function formatData($data, $comments = [], $prefix = ' ')
5353
$elements[] = $prefix . " */";
5454
}
5555

56-
$elements[] = $prefix . var_export($key, true) . ' => ' .
57-
(!is_array($value) ? var_export($value, true) . ',' : '');
56+
$elements[] = $prefix . $this->varExportShort($key) . ' => ' .
57+
(!is_array($value) ? $this->varExportShort($value) . ',' : '');
5858

5959
if (is_array($value)) {
60-
$elements[] = $prefix . 'array (';
60+
$elements[] = $prefix . '[';
6161
$elements[] = $this->formatData($value, [], ' ' . $prefix);
62-
$elements[] = $prefix . '),';
62+
$elements[] = $prefix . '],';
6363
}
6464
}
6565
return implode("\n", $elements);

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,68 +55,68 @@ public function formatWithCommentDataProvider()
5555
];
5656
$expectedResult1 = <<<TEXT
5757
<?php
58-
return array (
58+
return [
5959
'ns1' =>
60-
array (
60+
[
6161
's1' =>
62-
array (
62+
[
6363
0 => 's11',
6464
1 => 's12',
65-
),
65+
],
6666
's2' =>
67-
array (
67+
[
6868
0 => 's21',
6969
1 => 's22',
70-
),
71-
),
70+
],
71+
],
7272
/**
7373
* For the section: ns2
7474
* comment for namespace 2
7575
*/
7676
'ns2' =>
77-
array (
77+
[
7878
's1' =>
79-
array (
79+
[
8080
0 => 's11',
81-
),
82-
),
81+
],
82+
],
8383
'ns3' => 'just text',
8484
'ns4' => 'just text',
85-
);
85+
];
8686
8787
TEXT;
8888
$expectedResult2 = <<<TEXT
8989
<?php
90-
return array (
90+
return [
9191
/**
9292
* For the section: ns1
9393
* comment for' namespace 1
9494
*/
9595
'ns1' =>
96-
array (
96+
[
9797
's1' =>
98-
array (
98+
[
9999
0 => 's11',
100100
1 => 's12',
101-
),
101+
],
102102
's2' =>
103-
array (
103+
[
104104
0 => 's21',
105105
1 => 's22',
106-
),
107-
),
106+
],
107+
],
108108
/**
109109
* For the section: ns2
110110
* comment for namespace 2.
111111
* Next comment for' namespace 2
112112
*/
113113
'ns2' =>
114-
array (
114+
[
115115
's1' =>
116-
array (
116+
[
117117
0 => 's11',
118-
),
119-
),
118+
],
119+
],
120120
/**
121121
* For the section: ns3
122122
* comment for" namespace 3
@@ -127,7 +127,7 @@ public function formatWithCommentDataProvider()
127127
* comment for namespace 4
128128
*/
129129
'ns4' => 'just text',
130-
);
130+
];
131131
132132
TEXT;
133133

0 commit comments

Comments
 (0)