Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
class PhpFormatter implements FormatterInterface
{
/**
* 2 space indentation for array formatting
* 4 space indentation for array formatting
*/
const INDENT = ' ';
const INDENT = ' ';

/**
* Format deployment configuration.
Expand All @@ -39,7 +39,7 @@ public function format($data, array $comments = [])
* @param string $prefix
* @return string
*/
private function formatData($data, $comments = [], $prefix = ' ')
private function formatData($data, $comments = [], $prefix = ' ')
{
$elements = [];

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

$elements[] = $prefix . $this->varExportShort($key) . ' => ' .
(!is_array($value) ? $this->varExportShort($value) . ',' : '');

if (is_array($value)) {
$elements[] = $prefix . '[';
$elements[] = $this->formatData($value, [], ' ' . $prefix);
$elements[] = $prefix . $this->varExportShort($key) . ' => [';
$elements[] = $this->formatData($value, [], ' ' . $prefix);
$elements[] = $prefix . '],';
} else {
$elements[] = $prefix . $this->varExportShort($key) . ' => ' . $this->varExportShort($value) . ',';
}
}
return implode("\n", $elements);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,101 +56,91 @@ public function formatWithCommentDataProvider()
$expectedResult1 = <<<TEXT
<?php
return [
'ns1' =>
[
's1' =>
[
0 => 's11',
1 => 's12',
'ns1' => [
's1' => [
0 => 's11',
1 => 's12',
],
's2' => [
0 => 's21',
1 => 's22',
],
],
's2' =>
[
0 => 's21',
1 => 's22',
],
],
/**
* For the section: ns2
* comment for namespace 2
*/
'ns2' =>
[
's1' =>
[
0 => 's11',
/**
* For the section: ns2
* comment for namespace 2
*/
'ns2' => [
's1' => [
0 => 's11',
],
],
],
'ns3' => 'just text',
'ns4' => 'just text',
'ns3' => 'just text',
'ns4' => 'just text',
];

TEXT;
$expectedResult2 = <<<TEXT
<?php
return [
/**
* For the section: ns1
* comment for' namespace 1
*/
'ns1' =>
[
's1' =>
[
0 => 's11',
1 => 's12',
],
's2' =>
[
0 => 's21',
1 => 's22',
/**
* For the section: ns1
* comment for' namespace 1
*/
'ns1' => [
's1' => [
0 => 's11',
1 => 's12',
],
's2' => [
0 => 's21',
1 => 's22',
],
],
],
/**
* For the section: ns2
* comment for namespace 2.
* Next comment for' namespace 2
*/
'ns2' =>
[
's1' =>
[
0 => 's11',
/**
* For the section: ns2
* comment for namespace 2.
* Next comment for' namespace 2
*/
'ns2' => [
's1' => [
0 => 's11',
],
],
],
/**
* For the section: ns3
* comment for" namespace 3
*/
'ns3' => 'just text',
/**
* For the section: ns4
* comment for namespace 4
*/
'ns4' => 'just text',
/**
* For the section: ns3
* comment for" namespace 3
*/
'ns3' => 'just text',
/**
* For the section: ns4
* comment for namespace 4
*/
'ns4' => 'just text',
];

TEXT;

$expectedResult3 = <<<TEXT
<?php
return [
'ns1' => [
's1' => [
's11',
's12'
'ns1' => [
's1' => [
's11',
's12'
],
's2' => [
's21',
's22'
]
],
'ns2' => [
's1' => [
's11'
]
],
's2' => [
's21',
's22'
]
],
'ns2' => [
's1' => [
's11'
]
],
'ns3' => 'just text',
'ns4' => 'just text'
'ns3' => 'just text',
'ns4' => 'just text'
];

TEXT;
Expand Down