Updated Rector to commit 07cfc2754d59ecfcd411e813d9d5fd48def7c035

07cfc2754d [Performance][AutoImport] Verify already use last name usage on long name on NameImportingPostRector (#6264)
This commit is contained in:
Tomas Votruba 2024-08-29 20:19:35 +00:00
parent f9441cf43d
commit 334519dc5c
12 changed files with 115 additions and 16 deletions

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '816c73347df4a5e4da48903af1190c131fcccb8c';
public const PACKAGE_VERSION = '07cfc2754d59ecfcd411e813d9d5fd48def7c035';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-08-28 18:47:29';
public const RELEASE_DATE = '2024-08-30 03:16:45';
/**
* @var int
*/

View File

@ -71,6 +71,15 @@ final class NameImportingPostRector extends \Rector\PostRector\Rector\AbstractPo
if ($node->isSpecialClassName()) {
return null;
}
// verify long name, as short name verify may conflict
// see test PR: https://github.com/rectorphp/rector-src/pull/6208
// ref https://3v4l.org/21H5j vs https://3v4l.org/GIHSB
if (\substr_count($node->toCodeString(), '\\') > 1) {
$originalName = $node->getAttribute(AttributeKey::ORIGINAL_NAME);
if ($originalName instanceof Name && $originalName->getLast() === $originalName->toString()) {
return null;
}
}
if ($this->classNameImportSkipper->shouldSkipName($node, $this->currentUses)) {
return null;
}

View File

@ -79,14 +79,15 @@ final class UnusedImportRemovingPostRector extends \Rector\PostRector\Rector\Abs
if (!$node instanceof Name) {
return null;
}
$names[] = $node->toString();
if ($node instanceof FullyQualified) {
$originalName = $node->getAttribute(AttributeKey::ORIGINAL_NAME);
if ($originalName instanceof Name) {
// collect original Name as well to cover namespaced used
// collect original Name as cover namespaced used
$names[] = $originalName->toString();
return $node;
}
}
$names[] = $node->toString();
return $node;
});
return $names;

View File

@ -66,6 +66,7 @@ return array(
'PHPStan\\PhpDocParser\\Ast\\PhpDoc\\VarTagValueNode' => $vendorDir . '/phpstan/phpdoc-parser/src/Ast/PhpDoc/VarTagValueNode.php',
'PHPStan\\PhpDocParser\\Ast\\Type\\ArrayShapeItemNode' => $vendorDir . '/phpstan/phpdoc-parser/src/Ast/Type/ArrayShapeItemNode.php',
'PHPStan\\PhpDocParser\\Ast\\Type\\ArrayShapeNode' => $vendorDir . '/phpstan/phpdoc-parser/src/Ast/Type/ArrayShapeNode.php',
'PHPStan\\PhpDocParser\\Ast\\Type\\ArrayShapeUnsealedTypeNode' => $vendorDir . '/phpstan/phpdoc-parser/src/Ast/Type/ArrayShapeUnsealedTypeNode.php',
'PHPStan\\PhpDocParser\\Ast\\Type\\ArrayTypeNode' => $vendorDir . '/phpstan/phpdoc-parser/src/Ast/Type/ArrayTypeNode.php',
'PHPStan\\PhpDocParser\\Ast\\Type\\CallableTypeNode' => $vendorDir . '/phpstan/phpdoc-parser/src/Ast/Type/CallableTypeNode.php',
'PHPStan\\PhpDocParser\\Ast\\Type\\CallableTypeParameterNode' => $vendorDir . '/phpstan/phpdoc-parser/src/Ast/Type/CallableTypeParameterNode.php',

View File

@ -285,6 +285,7 @@ class ComposerStaticInitf022c0913f90a8ce8e0872b4624f9c82
'PHPStan\\PhpDocParser\\Ast\\PhpDoc\\VarTagValueNode' => __DIR__ . '/..' . '/phpstan/phpdoc-parser/src/Ast/PhpDoc/VarTagValueNode.php',
'PHPStan\\PhpDocParser\\Ast\\Type\\ArrayShapeItemNode' => __DIR__ . '/..' . '/phpstan/phpdoc-parser/src/Ast/Type/ArrayShapeItemNode.php',
'PHPStan\\PhpDocParser\\Ast\\Type\\ArrayShapeNode' => __DIR__ . '/..' . '/phpstan/phpdoc-parser/src/Ast/Type/ArrayShapeNode.php',
'PHPStan\\PhpDocParser\\Ast\\Type\\ArrayShapeUnsealedTypeNode' => __DIR__ . '/..' . '/phpstan/phpdoc-parser/src/Ast/Type/ArrayShapeUnsealedTypeNode.php',
'PHPStan\\PhpDocParser\\Ast\\Type\\ArrayTypeNode' => __DIR__ . '/..' . '/phpstan/phpdoc-parser/src/Ast/Type/ArrayTypeNode.php',
'PHPStan\\PhpDocParser\\Ast\\Type\\CallableTypeNode' => __DIR__ . '/..' . '/phpstan/phpdoc-parser/src/Ast/Type/CallableTypeNode.php',
'PHPStan\\PhpDocParser\\Ast\\Type\\CallableTypeParameterNode' => __DIR__ . '/..' . '/phpstan/phpdoc-parser/src/Ast/Type/CallableTypeParameterNode.php',

View File

@ -866,17 +866,17 @@
},
{
"name": "phpstan\/phpdoc-parser",
"version": "1.29.1",
"version_normalized": "1.29.1.0",
"version": "1.30.0",
"version_normalized": "1.30.0.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/phpstan\/phpdoc-parser.git",
"reference": "fcaefacf2d5c417e928405b71b400d4ce10daaf4"
"reference": "5ceb0e384997db59f38774bf79c2a6134252c08f"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpdoc-parser\/zipball\/fcaefacf2d5c417e928405b71b400d4ce10daaf4",
"reference": "fcaefacf2d5c417e928405b71b400d4ce10daaf4",
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpdoc-parser\/zipball\/5ceb0e384997db59f38774bf79c2a6134252c08f",
"reference": "5ceb0e384997db59f38774bf79c2a6134252c08f",
"shasum": ""
},
"require": {
@ -893,7 +893,7 @@
"phpunit\/phpunit": "^9.5",
"symfony\/process": "^5.2"
},
"time": "2024-05-31T08:52:43+00:00",
"time": "2024-08-29T09:54:52+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
@ -910,7 +910,7 @@
"description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": {
"issues": "https:\/\/github.com\/phpstan\/phpdoc-parser\/issues",
"source": "https:\/\/github.com\/phpstan\/phpdoc-parser\/tree\/1.29.1"
"source": "https:\/\/github.com\/phpstan\/phpdoc-parser\/tree\/1.30.0"
},
"install-path": "..\/phpstan\/phpdoc-parser"
},

File diff suppressed because one or more lines are too long

View File

@ -16,21 +16,24 @@ class ArrayShapeNode implements \PHPStan\PhpDocParser\Ast\Type\TypeNode
public $sealed;
/** @var self::KIND_* */
public $kind;
/** @var ArrayShapeUnsealedTypeNode|null */
public $unsealedType;
/**
* @param ArrayShapeItemNode[] $items
* @param self::KIND_* $kind
*/
public function __construct(array $items, bool $sealed = \true, string $kind = self::KIND_ARRAY)
public function __construct(array $items, bool $sealed = \true, string $kind = self::KIND_ARRAY, ?\PHPStan\PhpDocParser\Ast\Type\ArrayShapeUnsealedTypeNode $unsealedType = null)
{
$this->items = $items;
$this->sealed = $sealed;
$this->kind = $kind;
$this->unsealedType = $unsealedType;
}
public function __toString() : string
{
$items = $this->items;
if (!$this->sealed) {
$items[] = '...';
$items[] = '...' . $this->unsealedType;
}
return $this->kind . '{' . implode(', ', $items) . '}';
}

View File

@ -0,0 +1,28 @@
<?php
declare (strict_types=1);
namespace PHPStan\PhpDocParser\Ast\Type;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\NodeAttributes;
use function sprintf;
class ArrayShapeUnsealedTypeNode implements Node
{
use NodeAttributes;
/** @var TypeNode */
public $valueType;
/** @var TypeNode|null */
public $keyType;
public function __construct(\PHPStan\PhpDocParser\Ast\Type\TypeNode $valueType, ?\PHPStan\PhpDocParser\Ast\Type\TypeNode $keyType)
{
$this->valueType = $valueType;
$this->keyType = $keyType;
}
public function __toString() : string
{
if ($this->keyType !== null) {
return sprintf('<%s, %s>', $this->keyType, $this->valueType);
}
return sprintf('<%s>', $this->valueType);
}
}

View File

@ -3,6 +3,7 @@
declare (strict_types=1);
namespace PHPStan\PhpDocParser\Parser;
use PHPStan\ShouldNotHappenException;
use function chr;
use function hexdec;
use function octdec;
@ -35,6 +36,9 @@ class StringUnescaper
return chr((int) hexdec(substr($str, 1)));
}
if ($str[0] === 'u') {
if (!isset($matches[2])) {
throw new ShouldNotHappenException();
}
return self::codePointToUtf8((int) hexdec($matches[2]));
}
return chr((int) octdec($str));

View File

@ -567,6 +567,7 @@ class TypeParser
$tokens->consumeTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET);
$items = [];
$sealed = \true;
$unsealedType = null;
do {
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
if ($tokens->tryConsumeTokenType(Lexer::TOKEN_CLOSE_CURLY_BRACKET)) {
@ -574,6 +575,15 @@ class TypeParser
}
if ($tokens->tryConsumeTokenType(Lexer::TOKEN_VARIADIC)) {
$sealed = \false;
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET)) {
if ($kind === Ast\Type\ArrayShapeNode::KIND_ARRAY) {
$unsealedType = $this->parseArrayShapeUnsealedType($tokens);
} else {
$unsealedType = $this->parseListShapeUnsealedType($tokens);
}
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
}
$tokens->tryConsumeTokenType(Lexer::TOKEN_COMMA);
break;
}
@ -582,7 +592,7 @@ class TypeParser
} while ($tokens->tryConsumeTokenType(Lexer::TOKEN_COMMA));
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
$tokens->consumeTokenType(Lexer::TOKEN_CLOSE_CURLY_BRACKET);
return new Ast\Type\ArrayShapeNode($items, $sealed, $kind);
return new Ast\Type\ArrayShapeNode($items, $sealed, $kind, $unsealedType);
}
/** @phpstan-impure */
private function parseArrayShapeItem(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : Ast\Type\ArrayShapeItemNode
@ -634,6 +644,41 @@ class TypeParser
}
return $this->enrichWithAttributes($tokens, $key, $startLine, $startIndex);
}
/**
* @phpstan-impure
*/
private function parseArrayShapeUnsealedType(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : Ast\Type\ArrayShapeUnsealedTypeNode
{
$startLine = $tokens->currentTokenLine();
$startIndex = $tokens->currentTokenIndex();
$tokens->consumeTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET);
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
$valueType = $this->parse($tokens);
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
$keyType = null;
if ($tokens->tryConsumeTokenType(Lexer::TOKEN_COMMA)) {
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
$keyType = $valueType;
$valueType = $this->parse($tokens);
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
}
$tokens->consumeTokenType(Lexer::TOKEN_CLOSE_ANGLE_BRACKET);
return $this->enrichWithAttributes($tokens, new Ast\Type\ArrayShapeUnsealedTypeNode($valueType, $keyType), $startLine, $startIndex);
}
/**
* @phpstan-impure
*/
private function parseListShapeUnsealedType(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : Ast\Type\ArrayShapeUnsealedTypeNode
{
$startLine = $tokens->currentTokenLine();
$startIndex = $tokens->currentTokenIndex();
$tokens->consumeTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET);
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
$valueType = $this->parse($tokens);
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
$tokens->consumeTokenType(Lexer::TOKEN_CLOSE_ANGLE_BRACKET);
return $this->enrichWithAttributes($tokens, new Ast\Type\ArrayShapeUnsealedTypeNode($valueType, null), $startLine, $startIndex);
}
/**
* @phpstan-impure
*/

View File

@ -44,6 +44,7 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\UsesTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeItemNode;
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode;
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeUnsealedTypeNode;
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode;
use PHPStan\PhpDocParser\Ast\Type\CallableTypeParameterNode;
@ -159,6 +160,12 @@ final class Printer
$isOptional = $node->isOptional ? '=' : '';
return trim("{$type}{$isReference}{$isVariadic}{$node->parameterName}") . $isOptional;
}
if ($node instanceof ArrayShapeUnsealedTypeNode) {
if ($node->keyType !== null) {
return sprintf('<%s, %s>', $this->printType($node->keyType), $this->printType($node->valueType));
}
return sprintf('<%s>', $this->printType($node->valueType));
}
if ($node instanceof DoctrineAnnotation) {
return (string) $node;
}
@ -287,7 +294,7 @@ final class Printer
return $this->printType($item);
}, $node->items);
if (!$node->sealed) {
$items[] = '...';
$items[] = '...' . ($node->unsealedType === null ? '' : $this->print($node->unsealedType));
}
return $node->kind . '{' . implode(', ', $items) . '}';
}