Skip to content

Commit

Permalink
[DX] Use direct method on node, instead of token position (#2340)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed May 21, 2022
1 parent fcadc67 commit b4120a8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
2 changes: 0 additions & 2 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::NEXT_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::PREVIOUS_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::START_TOKEN_POSITION,
\Rector\NodeTypeResolver\Node\AttributeKey::ORIGINAL_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::IS_UNREACHABLE,
\Rector\NodeTypeResolver\Node\AttributeKey::PHP_DOC_INFO,
Expand All @@ -70,7 +69,6 @@
\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::NEXT_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::PREVIOUS_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::START_TOKEN_POSITION,
\Rector\NodeTypeResolver\Node\AttributeKey::ORIGINAL_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::IS_UNREACHABLE,
\Rector\NodeTypeResolver\Node\AttributeKey::PHP_DOC_INFO,
Expand Down
6 changes: 0 additions & 6 deletions packages/NodeTypeResolver/Node/AttributeKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ final class AttributeKey
*/
public const SCOPE = 'scope';

/**
* @deprecated Use @see \Rector\Naming\Naming\UseImportsResolver::resolveForNode() instead
* @var string
*/
public const USE_NODES = 'useNodes';

/**
* Internal php-parser name.
* Do not change this even if you want!
Expand Down
11 changes: 6 additions & 5 deletions rules/DeadCode/NodeCollector/NodeByTypeAndPositionCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ public function collectNodesByTypeAndPosition(
$nodesByTypeAndPosition = [];

foreach ($assignedVariables as $assignedVariable) {
$startTokenPos = $assignedVariable->getAttribute(AttributeKey::START_TOKEN_POSITION);
$startTokenPos = $assignedVariable->getStartTokenPos();

if ($startTokenPos === null) {
// "-1" is empty value default
if ($startTokenPos === -1) {
continue;
}

Expand All @@ -58,10 +59,10 @@ public function collectNodesByTypeAndPosition(
}

foreach ($assignedVariablesUse as $assignedVariableUse) {
/** @var int|null $startTokenPos */
$startTokenPos = $assignedVariableUse->getAttribute(AttributeKey::START_TOKEN_POSITION);
$startTokenPos = $assignedVariableUse->getStartTokenPos();

if ($startTokenPos === null) {
// "-1" is empty value default
if ($startTokenPos === -1) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,10 @@ public function provideMinPhpVersion(): int

private function shouldSkip(LNumber | DNumber $node, string $numericValueAsString): bool
{
/** @var int $startToken */
$startToken = $node->getAttribute(AttributeKey::START_TOKEN_POSITION);
$startTokenPos = $node->getStartTokenPos();

$oldTokens = $this->file->getOldTokens();
$tokenValue = $oldTokens[$startToken][1] ?? null;
$tokenValue = $oldTokens[$startTokenPos][1] ?? null;

if (! is_string($tokenValue)) {
return true;
Expand Down

0 comments on commit b4120a8

Please sign in to comment.