diff --git a/scoper.php b/scoper.php index 92cfa996c99..c1def570660 100644 --- a/scoper.php +++ b/scoper.php @@ -74,7 +74,10 @@ // make external rules easier to write without enforing getRuleDefinition() // as they are not designed for open-sourcing static function (string $filePath, string $prefix, string $content): string { - if (!\str_ends_with($filePath, 'vendor/symplify/rule-doc-generator-contracts/src/Contract/DocumentedRuleInterface.php')) { + if (! \str_ends_with( + $filePath, + 'vendor/symplify/rule-doc-generator-contracts/src/Contract/DocumentedRuleInterface.php' + )) { return $content; } diff --git a/src/BetterPhpDocParser/PhpDocNodeVisitor/TemplatePhpDocNodeVisitor.php b/src/BetterPhpDocParser/PhpDocNodeVisitor/TemplatePhpDocNodeVisitor.php index 7014055361e..366948ad7af 100644 --- a/src/BetterPhpDocParser/PhpDocNodeVisitor/TemplatePhpDocNodeVisitor.php +++ b/src/BetterPhpDocParser/PhpDocNodeVisitor/TemplatePhpDocNodeVisitor.php @@ -4,6 +4,7 @@ namespace Rector\BetterPhpDocParser\PhpDocNodeVisitor; +use PHPStan\PhpDocParser\Ast\Attribute; use PHPStan\PhpDocParser\Ast\Node; use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode; use PHPStan\PhpDocParser\Lexer\Lexer; @@ -12,8 +13,6 @@ use Rector\BetterPhpDocParser\DataProvider\CurrentTokenIteratorProvider; use Rector\BetterPhpDocParser\ValueObject\Parser\BetterTokenIterator; use Rector\BetterPhpDocParser\ValueObject\PhpDoc\SpacingAwareTemplateTagValueNode; -use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey; -use Rector\BetterPhpDocParser\ValueObject\StartAndEnd; use Rector\Exception\ShouldNotHappenException; use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\AbstractPhpDocNodeVisitor; @@ -37,12 +36,13 @@ public function enterNode(Node $node): ?Node $betterTokenIterator = $this->currentTokenIteratorProvider->provide(); - $startAndEnd = $node->getAttribute(PhpDocAttributeKey::START_AND_END); - if (! $startAndEnd instanceof StartAndEnd) { + $startIndex = $node->getAttribute(Attribute::START_INDEX); + $endIndex = $node->getAttribute(Attribute::END_INDEX); + if ($startIndex === null || $endIndex === null) { throw new ShouldNotHappenException(); } - $prepositions = $this->resolvePreposition($betterTokenIterator, $startAndEnd); + $prepositions = $this->resolvePreposition($betterTokenIterator, $startIndex, $endIndex); $spacingAwareTemplateTagValueNode = new SpacingAwareTemplateTagValueNode( $node->name, $node->bound, @@ -55,9 +55,12 @@ public function enterNode(Node $node): ?Node return $spacingAwareTemplateTagValueNode; } - private function resolvePreposition(BetterTokenIterator $betterTokenIterator, StartAndEnd $startAndEnd): string - { - $partialTokens = $betterTokenIterator->partialTokens($startAndEnd->getStart(), $startAndEnd->getEnd()); + private function resolvePreposition( + BetterTokenIterator $betterTokenIterator, + int $startIndex, + int $endIndex + ): string { + $partialTokens = $betterTokenIterator->partialTokens($startIndex, $endIndex); foreach ($partialTokens as $partialToken) { if ($partialToken[1] !== Lexer::TOKEN_IDENTIFIER) { diff --git a/src/BetterPhpDocParser/ValueObject/Parser/BetterTokenIterator.php b/src/BetterPhpDocParser/ValueObject/Parser/BetterTokenIterator.php index 3796e03691e..55c25bafd35 100644 --- a/src/BetterPhpDocParser/ValueObject/Parser/BetterTokenIterator.php +++ b/src/BetterPhpDocParser/ValueObject/Parser/BetterTokenIterator.php @@ -96,7 +96,7 @@ public function count(): int */ public function partialTokens(int $start, int $end): array { - return array_slice($this->getTokens(), $start, $end); + return array_slice($this->getTokens(), $start, $end - $start + 1); } public function containsTokenType(int $type): bool diff --git a/tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/FixtureBasic/generic_method.txt b/tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/FixtureBasic/generic_method.txt new file mode 100644 index 00000000000..9b1e3b75f8c --- /dev/null +++ b/tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfoPrinter/FixtureBasic/generic_method.txt @@ -0,0 +1 @@ +/** @method T foo(T $bar) */