Skip to content

Commit

Permalink
bug PHP-CS-Fixer#813 MultilineArrayTrailingCommaFixer - do not move a…
Browse files Browse the repository at this point in the history
…rray end to new line (keradus)

This PR was merged into the 1.4-dev branch.

Discussion
----------

MultilineArrayTrailingCommaFixer - do not move array end to new line

Currently
```php
<?php
    $var = array(
        "string",
        /* foo */);
```

is changed:
```diff
 <?php
     $var = array(
-        "string"
-        /* foo */);
+        "string",
+        /* foo */
+);
```
First, this fixer is not supposed to move end of array, and next, the end of array is wrongly placed (no indent)

The fixer should only add a comma, like:
```diff
 <?php
     $var = array(
-        "string"
+        "string",
         /* foo */);
```

Commits
-------

31c3e76 MultilineArrayTrailingCommaFixer - do not move array end to new line
  • Loading branch information
keradus committed Dec 12, 2014
2 parents 3027bfe + 31c3e76 commit 343b88d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Symfony/CS/Fixer/Symfony/MultilineArrayTrailingCommaFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ private function fixArray(Tokens $tokens, $index)
if ($startIndex !== $beforeEndIndex && !$beforeEndToken->equalsAny(array(',', array(T_END_HEREDOC)))) {
$tokens->insertAt($beforeEndIndex + 1, new Token(','));

if ($tokens[$endIndex]->isComment()) {
$tokens->ensureWhitespaceAtIndex($endIndex, 1, "\n");
} elseif (!$tokens[$endIndex]->isWhitespace()) {
$endToken = $tokens[$endIndex];

if (!$endToken->isComment() && !$endToken->isWhitespace()) {
$tokens->ensureWhitespaceAtIndex($endIndex, 1, ' ');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,26 @@ function foo(array $a)
//comment
);',
),
array(
'<?php
$var = array(
"string",
/* foo */);',
'<?php
$var = array(
"string"
/* foo */);',
),
array(
'<?php
$var = [
"string",
/* foo */];',
'<?php
$var = [
"string"
/* foo */];',
),
);
}
}

0 comments on commit 343b88d

Please sign in to comment.