mirror of https://github.com/rectorphp/rector.git
[DX] Use direct method on node, instead of token position (#2340)
This commit is contained in:
parent
fcadc67328
commit
b4120a8850
|
@ -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,
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue