Updated Rector to commit d2c420909ad90503131eb2c9936d1d12ec8ba38c

d2c420909a [BetterPhpDocParser] Remove unnecessary PrivatesAccessor usage on BetterTokenIterator and TokenIteratorFactory (#5950)
This commit is contained in:
Tomas Votruba 2024-06-06 22:25:08 +00:00
parent 3f16b6500c
commit 125524cee4
3 changed files with 9 additions and 34 deletions

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '962912da397184365e95f794cc8cfe0ece2125dd';
public const PACKAGE_VERSION = 'd2c420909ad90503131eb2c9936d1d12ec8ba38c';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-06-06 21:21:45';
public const RELEASE_DATE = '2024-06-07 05:21:39';
/**
* @var int
*/

View File

@ -6,7 +6,6 @@ namespace Rector\BetterPhpDocParser\PhpDocInfo;
use PHPStan\PhpDocParser\Lexer\Lexer;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use Rector\BetterPhpDocParser\ValueObject\Parser\BetterTokenIterator;
use Rector\Util\Reflection\PrivatesAccessor;
final class TokenIteratorFactory
{
/**
@ -14,19 +13,9 @@ final class TokenIteratorFactory
* @var \PHPStan\PhpDocParser\Lexer\Lexer
*/
private $lexer;
/**
* @readonly
* @var \Rector\Util\Reflection\PrivatesAccessor
*/
private $privatesAccessor;
/**
* @var string
*/
private const INDEX = 'index';
public function __construct(Lexer $lexer, PrivatesAccessor $privatesAccessor)
public function __construct(Lexer $lexer)
{
$this->lexer = $lexer;
$this->privatesAccessor = $privatesAccessor;
}
public function create(string $content) : BetterTokenIterator
{
@ -38,11 +27,9 @@ final class TokenIteratorFactory
if ($tokenIterator instanceof BetterTokenIterator) {
return $tokenIterator;
}
$tokens = $this->privatesAccessor->getPrivateProperty($tokenIterator, 'tokens');
$betterTokenIterator = new BetterTokenIterator($tokens);
// keep original position
$currentIndex = $this->privatesAccessor->getPrivateProperty($tokenIterator, self::INDEX);
$this->privatesAccessor->setPrivateProperty($betterTokenIterator, self::INDEX, $currentIndex);
return $betterTokenIterator;
// keep original tokens and index position
$tokens = $tokenIterator->getTokens();
$currentIndex = $tokenIterator->currentTokenIndex();
return new BetterTokenIterator($tokens, $currentIndex);
}
}

View File

@ -5,29 +5,17 @@ namespace Rector\BetterPhpDocParser\ValueObject\Parser;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use Rector\Exception\ShouldNotHappenException;
use Rector\Util\Reflection\PrivatesAccessor;
final class BetterTokenIterator extends TokenIterator
{
/**
* @var string
*/
private const TOKENS = 'tokens';
/**
* @var string
*/
private const INDEX = 'index';
/**
* @param array<int, mixed> $tokens
*/
public function __construct(array $tokens, int $index = 0)
{
$privatesAccessor = new PrivatesAccessor();
if ($tokens === []) {
$privatesAccessor->setPrivateProperty($this, self::TOKENS, []);
$privatesAccessor->setPrivateProperty($this, self::INDEX, 0);
} else {
parent::__construct($tokens, $index);
$index = 0;
}
parent::__construct($tokens, $index);
}
/**
* @param int[] $types