diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java b/php/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java index b23284d349e5..22eb8745f9cc 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java @@ -300,6 +300,7 @@ public void visit(ArrayCreation node) { if (formatTokens.get(formatTokens.size() - 1).getId() == FormatToken.Kind.WHITESPACE_INDENT || path.get(1) instanceof ArrayElement || path.get(1) instanceof FormalParameter + || path.get(1) instanceof MatchArm || path.get(1) instanceof CastExpression) { // when the array is on the beginning of the line, indent items in normal way delta = options.indentArrayItems; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/php80/matchExpressionWithArray_01.php b/php/php.editor/test/unit/data/testfiles/formatting/php80/matchExpressionWithArray_01.php new file mode 100644 index 000000000000..4e7066e5c26c --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/php80/matchExpressionWithArray_01.php @@ -0,0 +1,37 @@ + [ + 'key' => 'value', + ], +}; + +match (true) { +'test1' => ['key' => 'value'], +'test2' => [ +'key1' => 'value1', +'nested' => [ +'key2' => 'value2', +], +], +}; diff --git a/php/php.editor/test/unit/data/testfiles/formatting/php80/matchExpressionWithArray_01.php.formatted b/php/php.editor/test/unit/data/testfiles/formatting/php80/matchExpressionWithArray_01.php.formatted new file mode 100644 index 000000000000..7b3e89b8d4b9 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/php80/matchExpressionWithArray_01.php.formatted @@ -0,0 +1,37 @@ + [ + 'key' => 'value', + ], +}; + +match (true) { + 'test1' => ['key' => 'value'], + 'test2' => [ + 'key1' => 'value1', + 'nested' => [ + 'key2' => 'value2', + ], + ], +}; diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterTest.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterTest.java index 0ec678672652..6feeccc9e879 100644 --- a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterTest.java +++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterTest.java @@ -943,6 +943,12 @@ public void testMatchExpressionSameLineBracePlacement_02() throws Exception { reformatFileContents("testfiles/formatting/php80/matchExpression_SameLine_02.php", options); } + // GH-5186 + public void testMatchExpressionWithArray_01() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + reformatFileContents("testfiles/formatting/php80/matchExpressionWithArray_01.php", options); + } + public void testAttributeSyntax_01() throws Exception { HashMap options = new HashMap<>(FmtOptions.getDefaults()); reformatFileContents("testfiles/formatting/php80/attributeSyntax_01.php", options);