From 018c1117d877021e0a684694040fa4525a9d527d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Mart=C3=ADnez?= Date: Fri, 13 Oct 2017 20:35:58 +0200 Subject: [PATCH 1/5] Rewrite PhpFormatter::format method, to avoid add extra spaces --- .../DeploymentConfig/Writer/PhpFormatter.php | 47 +++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php index b62f841d526aa..e466bb40a2210 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php @@ -1,6 +1,6 @@ formatData($data, $comments, ' ') . "\n);\n"; + } + return " $value) { - $comment = ' '; if (!empty($comments[$key])) { - $comment = " /**\n * " . str_replace("\n", "\n * ", var_export($comments[$key], true)) . "\n */\n"; + $elements[] = $prefix . '/**'; + $elements[] = $prefix . ' * For the section: ' . $key; + + foreach (explode("\n", $comments[$key]) as $commentLine) { + $elements[] = $prefix . ' * ' . $commentLine; + } + + $elements[] = $prefix . " */"; + } + + if (is_array($value)) { + $elements[] = $prefix . var_export($key, true) . ' => '; + $elements[] = $prefix . 'array ('; + $elements[] = $this->formatData($value, [], ' ' . $prefix); + $elements[] = $prefix . '),'; + } else { + $elements[] = $prefix . var_export($key, true) . ' => ' . var_export($value, true) . ','; } - $space = is_array($value) ? " \n" : ' '; - $elements[] = $comment . var_export($key, true) . ' =>' . $space . var_export($value, true); } - return " Date: Sat, 14 Oct 2017 01:26:43 +0200 Subject: [PATCH 2/5] Remove else statement as indicated by Codacy --- .../Framework/App/DeploymentConfig/Writer/PhpFormatter.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php index e466bb40a2210..319269bd0011d 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php @@ -51,13 +51,13 @@ protected function formatData($data, $comments, $prefix = '') $elements[] = $prefix . " */"; } + $elements[] = $prefix . var_export($key, true) . ' => ' . + (!is_array($value) ? var_export($value, true) . ',' : ''); + if (is_array($value)) { - $elements[] = $prefix . var_export($key, true) . ' => '; $elements[] = $prefix . 'array ('; $elements[] = $this->formatData($value, [], ' ' . $prefix); $elements[] = $prefix . '),'; - } else { - $elements[] = $prefix . var_export($key, true) . ' => ' . var_export($value, true) . ','; } } return implode("\n", $elements); From 081f4c6ad2cbe3a6809915f49ef233f8e526399e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Mart=C3=ADnez?= Date: Sat, 14 Oct 2017 04:51:07 +0200 Subject: [PATCH 3/5] Update unit tests --- .../Test/Unit/DeploymentConfig/Writer/PhpFormatterTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 6d6c0fa58b343..eafb7daa7af55 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 @@ -6,7 +6,7 @@ namespace Magento\Framework\App\Test\Unit\DeploymentConfig\Writer; -use \Magento\Framework\App\DeploymentConfig\Writer\PhpFormatter; +use Magento\Framework\App\DeploymentConfig\Writer\PhpFormatter; class PhpFormatterTest extends \PHPUnit_Framework_TestCase { @@ -78,7 +78,7 @@ public function formatWithCommentDataProvider() ), ), 'ns3' => 'just text', - 'ns4' => 'just text' + 'ns4' => 'just text', ); TEXT; @@ -119,7 +119,7 @@ public function formatWithCommentDataProvider() /** * 'comment for namespace 4' */ - 'ns4' => 'just text' + 'ns4' => 'just text', ); TEXT; From c4fb81f69c5a6fc157f1858f1e74157c1e125f8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Mart=C3=ADnez?= Date: Sun, 15 Oct 2017 16:29:45 +0200 Subject: [PATCH 4/5] Update tests --- .../Writer/PhpFormatterTest.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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 eafb7daa7af55..47b6ca0147168 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 @@ -68,7 +68,8 @@ public function formatWithCommentDataProvider() ), ), /** - * 'comment for namespace 2' + * For the section: ns2 + * comment for namespace 2 */ 'ns2' => array ( @@ -86,7 +87,8 @@ public function formatWithCommentDataProvider() array ( @@ -102,8 +104,9 @@ public function formatWithCommentDataProvider() ), ), /** - * 'comment for namespace 2. - * Next comment for namespace 2' + * For the section: ns2 + * comment for namespace 2. + * Next comment for namespace 2 */ 'ns2' => array ( @@ -113,11 +116,13 @@ public function formatWithCommentDataProvider() ), ), /** - * 'comment for namespace 3' + * For the section: ns3 + * comment for namespace 3 */ 'ns3' => 'just text', /** - * 'comment for namespace 4' + * For the section: ns4 + * comment for namespace 4 */ 'ns4' => 'just text', ); From 1a28e453607b6ca2528b26856ebc1a5d429fae78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Mart=C3=ADnez?= Date: Sun, 15 Oct 2017 17:40:51 +0200 Subject: [PATCH 5/5] Update doc blocks for static tests --- .../DeploymentConfig/Writer/PhpFormatter.php | 8 ++++---- .../Writer/PhpFormatterTest.php | 20 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php index 319269bd0011d..b419b3827e5ff 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php @@ -21,7 +21,7 @@ class PhpFormatter implements FormatterInterface public function format($data, array $comments = []) { if (!empty($comments) && is_array($data)) { - return "formatData($data, $comments, ' ') . "\n);\n"; + return "formatData($data, $comments) . "\n);\n"; } return "assertEquals($expectedResult, $formatter->format($data, $comments)); } + /** + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ public function formatWithCommentDataProvider() { $array = [ @@ -45,9 +47,9 @@ public function formatWithCommentDataProvider() ]; $comments1 = ['ns2' => 'comment for namespace 2']; $comments2 = [ - 'ns1' => 'comment for namespace 1', - 'ns2' => "comment for namespace 2.\nNext comment for namespace 2", - 'ns3' => 'comment for namespace 3', + 'ns1' => 'comment for\' namespace 1', + 'ns2' => "comment for namespace 2.\nNext comment for' namespace 2", + 'ns3' => 'comment for" namespace 3', 'ns4' => 'comment for namespace 4', 'ns5' => 'comment for unexisted namespace 5', ]; @@ -88,7 +90,7 @@ public function formatWithCommentDataProvider() return array ( /** * For the section: ns1 - * comment for namespace 1 + * comment for' namespace 1 */ 'ns1' => array ( @@ -106,7 +108,7 @@ public function formatWithCommentDataProvider() /** * For the section: ns2 * comment for namespace 2. - * Next comment for namespace 2 + * Next comment for' namespace 2 */ 'ns2' => array ( @@ -117,7 +119,7 @@ public function formatWithCommentDataProvider() ), /** * For the section: ns3 - * comment for namespace 3 + * comment for" namespace 3 */ 'ns3' => 'just text', /**