[DX] Use direct method on node, instead of token position (#2340)

This commit is contained in:
Tomas Votruba 2022-05-21 10:43:58 +02:00 committed by GitHub
parent fcadc67328
commit b4120a8850
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 16 deletions

View File

@ -50,7 +50,6 @@ expectedArguments(
\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,
@ -70,7 +69,6 @@ expectedArguments(
\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,

View File

@ -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!

View File

@ -33,9 +33,10 @@ final class NodeByTypeAndPositionCollector
$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;
}
@ -58,10 +59,10 @@ final class NodeByTypeAndPositionCollector
}
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;
}

View File

@ -139,11 +139,10 @@ CODE_SAMPLE
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;