|
@@ -64,7 +64,10 @@ include_once("sample4.php");
|
|
|
{
|
|
|
foreach (array_reverse($includies) as $includy) {
|
|
|
if ($includy['end'] && !$tokens[$includy['end']]->isGivenKind(T_CLOSE_TAG)) {
|
|
|
- $tokens->removeLeadingWhitespace($includy['end']);
|
|
|
+ $afterEndIndex = $tokens->getNextNonWhitespace($includy['end']);
|
|
|
+ if (null === $afterEndIndex || !$tokens[$afterEndIndex]->isComment()) {
|
|
|
+ $tokens->removeLeadingWhitespace($includy['end']);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$braces = $includy['braces'];
|
|
@@ -73,13 +76,15 @@ include_once("sample4.php");
|
|
|
$nextToken = $tokens[$tokens->getNextMeaningfulToken($braces['close'])];
|
|
|
|
|
|
if ($nextToken->equalsAny(array(';', array(T_CLOSE_TAG)))) {
|
|
|
- $tokens->removeLeadingWhitespace($braces['open']);
|
|
|
- $tokens->removeTrailingWhitespace($braces['open']);
|
|
|
- $tokens->removeLeadingWhitespace($braces['close']);
|
|
|
- $tokens->removeTrailingWhitespace($braces['close']);
|
|
|
-
|
|
|
- $tokens[$braces['open']] = new Token(array(T_WHITESPACE, ' '));
|
|
|
- $tokens[$braces['close']]->clear();
|
|
|
+ $this->removeWhitespaceAroundIfPossible($tokens, $braces['open']);
|
|
|
+ $this->removeWhitespaceAroundIfPossible($tokens, $braces['close']);
|
|
|
+ $tokens->clearTokenAndMergeSurroundingWhitespace($braces['open']);
|
|
|
+ $tokens->clearTokenAndMergeSurroundingWhitespace($braces['close']);
|
|
|
+
|
|
|
+ $nextSiblingIndex = $tokens->getNonEmptySibling($includy['begin'], 1);
|
|
|
+ if (!$tokens[$nextSiblingIndex]->isWhitespace()) {
|
|
|
+ $tokens->insertAt($nextSiblingIndex, new Token(array(T_WHITESPACE, ' ')));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -134,4 +139,21 @@ include_once("sample4.php");
|
|
|
|
|
|
return $includies;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param Tokens $tokens
|
|
|
+ * @param int $index
|
|
|
+ */
|
|
|
+ private function removeWhitespaceAroundIfPossible(Tokens $tokens, $index)
|
|
|
+ {
|
|
|
+ $nextIndex = $tokens->getNextNonWhitespace($index);
|
|
|
+ if (null === $nextIndex || !$tokens[$nextIndex]->isComment()) {
|
|
|
+ $tokens->removeLeadingWhitespace($index);
|
|
|
+ }
|
|
|
+
|
|
|
+ $prevIndex = $tokens->getPrevNonWhitespace($index);
|
|
|
+ if (null === $prevIndex || !$tokens[$prevIndex]->isComment()) {
|
|
|
+ $tokens->removeTrailingWhitespace($index);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|