From 3cc44982067c759ed1d4a4dc7d91e5d20ade5b61 Mon Sep 17 00:00:00 2001 From: Andreas von Studnitz Date: Thu, 22 Mar 2018 09:42:54 +0200 Subject: [PATCH] Improve array output format by using 4 instead of 2 spaces and removing whitelines after "=>". --- .../DeploymentConfig/Writer/PhpFormatter.php | 15 +- .../Writer/PhpFormatterTest.php | 144 ++++++++---------- 2 files changed, 74 insertions(+), 85 deletions(-) diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php index 030fc72608161..d5a89c56b689f 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php @@ -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. @@ -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 = []; @@ -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); diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/Writer/PhpFormatterTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/Writer/PhpFormatterTest.php index cc673e084c3b2..1967a39fe4374 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/Writer/PhpFormatterTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/Writer/PhpFormatterTest.php @@ -56,77 +56,67 @@ public function formatWithCommentDataProvider() $expectedResult1 = << - [ - '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 = << - [ - '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; @@ -134,23 +124,23 @@ public function formatWithCommentDataProvider() $expectedResult3 = << [ - '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;