Skip to content

Commit

Permalink
Rename TokenCollection methods to minimise overlap with Token
Browse files Browse the repository at this point in the history
- `setWhitespace()` -> `setTokenWhitespace()`
- `applyWhitespace()` -> `applyTokenWhitespace()`
  • Loading branch information
lkrms committed Jan 17, 2025
1 parent ac432a1 commit 4860070
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/Internal/TokenCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public function toString(string $delimiter = ''): string
/**
* @return $this
*/
public function setWhitespace(int $whitespace): self
public function setTokenWhitespace(int $whitespace): self
{
foreach ($this->Items as $token) {
$token->Whitespace |= $whitespace;
Expand All @@ -335,7 +335,7 @@ public function setWhitespace(int $whitespace): self
/**
* @return $this
*/
public function applyWhitespace(int $whitespace): self
public function applyTokenWhitespace(int $whitespace): self
{
// Shift *_BEFORE and *_AFTER to their NO_* counterparts, then clear
// other bits
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/SemiStrictExpressions.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function processTokens(array $tokens): void
if ($token->id === \T_FOR) {
/** @var TokenCollection */
$semicolons = $token->Data[Data::FOR_PARTS][3];
$semicolons->setWhitespace(Space::LINE_AFTER);
$semicolons->setTokenWhitespace(Space::LINE_AFTER);

Check warning on line 76 in src/Rule/SemiStrictExpressions.php

View check run for this annotation

Codecov / codecov/patch

src/Rule/SemiStrictExpressions.php#L75-L76

Added lines #L75 - L76 were not covered by tests
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/StandardSpacing.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ static function () use ($idx, $innerIndent, $next, $last) {
foreach ([$expr1, $expr2, $expr3] as $i => $expr) {
$count = $expr->count();
if ($i < 2 && $count === 1) {
$expr->setWhitespace(Space::NONE_BEFORE);
$expr->setTokenWhitespace(Space::NONE_BEFORE);
} elseif ($i === 2 && $count === 0) {
/** @var Token */
$semi2 = $semicolons->last();
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/StrictExpressions.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function processTokens(array $tokens): void
if ($token->id === \T_FOR) {
/** @var TokenCollection */
$semicolons = $token->Data[Data::FOR_PARTS][3];
$semicolons->setWhitespace(Space::LINE_AFTER);
$semicolons->setTokenWhitespace(Space::LINE_AFTER);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Rule/StrictLists.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function processList(Token $parent, TokenCollection $items, Token $lastCh
) {
$items = $items->shift();
}
$items->applyWhitespace(Space::LINE_BEFORE);
$items->applyTokenWhitespace(Space::LINE_BEFORE);
} else {
$items->setWhitespace(Space::NO_BLANK_BEFORE | Space::NO_LINE_BEFORE);
$items->setTokenWhitespace(Space::NO_BLANK_BEFORE | Space::NO_LINE_BEFORE);
}
}
}
12 changes: 6 additions & 6 deletions src/Rule/VerticalSpacing.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@ public function processTokens(array $tokens): void
}
}
if ($hasNewlineAndComma) {
$commas->setWhitespace(Space::LINE_AFTER);
$semicolons->setWhitespace(Space::BLANK_AFTER);
$commas->setTokenWhitespace(Space::LINE_AFTER);
$semicolons->setTokenWhitespace(Space::BLANK_AFTER);
} elseif ($hasNewline || $semicolons->tokenHasNewlineAfter()) {
$semicolons->setWhitespace(Space::LINE_AFTER);
$semicolons->setTokenWhitespace(Space::LINE_AFTER);
}
} elseif ($token->id === \T_OPEN_BRACE) {
if (
Expand Down Expand Up @@ -351,7 +351,7 @@ public function processTokens(array $tokens): void
$chain = $chain->shift();
}

$chain->setWhitespace(Space::LINE_BEFORE);
$chain->setTokenWhitespace(Space::LINE_BEFORE);
}
}
}
Expand Down Expand Up @@ -388,7 +388,7 @@ public function processList(Token $parent, TokenCollection $items, Token $lastCh
if ($lastChild->id === \T_COMMA) {
$parent->Whitespace |= Space::LINE_AFTER;
$items->add($parent->CloseBracket)
->applyWhitespace(Space::LINE_BEFORE);
->applyTokenWhitespace(Space::LINE_BEFORE);
}

if ($parent->id === \T_OPEN_PARENTHESIS && $parent->isParameterList()) {
Expand Down Expand Up @@ -424,7 +424,7 @@ public function processDeclarations(array $declarations): void
!$this->ListRuleEnabled
&& $commas->tokenHasNewlineBeforeNextCode()
)) {
$commas->setWhitespace(Space::LINE_AFTER);
$commas->setTokenWhitespace(Space::LINE_AFTER);
}
}

Expand Down

0 comments on commit 4860070

Please sign in to comment.