FPPP: Fix indentation on list insertion

Use indentation of last list element, instead of indentation
before the insertion point.

Fixes #466.
This commit is contained in:
Nikita Popov 2018-01-25 22:08:40 +01:00
parent aa685e711a
commit 4dacbb8d39
3 changed files with 26 additions and 2 deletions

View File

@ -1,6 +1,11 @@
Version 4.0.0-dev
-----------------
### Fixed
* In formatting-preserving pretty printer:
* Fixed indentation when inserting into lists. (#466)
### Added
* In formatting-preserving pretty printer:

View File

@ -700,6 +700,7 @@ abstract class PrettyPrinterAbstract
$beforeFirstKeepOrReplace = true;
$delayedAdd = [];
$lastElemIndentLevel = $this->indentLevel;
$insertNewline = false;
if ($insertStr === "\n") {
@ -756,7 +757,8 @@ abstract class PrettyPrinterAbstract
}
$origIndentLevel = $this->indentLevel;
$this->setIndentLevel($this->origTokens->getIndentationBefore($itemStartPos) + $indentAdjustment);
$lastElemIndentLevel = $this->origTokens->getIndentationBefore($itemStartPos) + $indentAdjustment;
$this->setIndentLevel($lastElemIndentLevel);
$comments = $arrItem->getComments();
$origComments = $origArrItem->getComments();
@ -825,7 +827,7 @@ abstract class PrettyPrinterAbstract
$itemEndPos = $pos - 1;
$origIndentLevel = $this->indentLevel;
$this->setIndentLevel($this->origTokens->getIndentationBefore($itemStartPos) + $indentAdjustment);
$this->setIndentLevel($lastElemIndentLevel);
if ($insertNewline) {
$comments = $arrItem->getComments();

View File

@ -0,0 +1,17 @@
Check correct indentation use when inserting into list node
-----
<?php
$this->foo = new Foo;
$this->foo->a()
->b();
-----
$outerCall = $stmts[1]->expr;
$innerCall = $outerCall->var;
$var = $innerCall->var;
$stmts[1]->expr = $innerCall;
$stmts[2] = new Stmt\Expression(new Expr\MethodCall($var, $outerCall->name));
-----
<?php
$this->foo = new Foo;
$this->foo->a();
$this->foo->b();