Updated Rector to commit 76714b95f240409a6fad92725ea19c870ed3ff14

76714b95f2 [Printer] Remove unnecessary BetterStandardPrinter::pStmt_Use() (#5478)
This commit is contained in:
Tomas Votruba 2024-01-18 20:41:36 +00:00
parent 08a112c644
commit f605aeb93f
11 changed files with 22 additions and 51 deletions

View File

@ -174,12 +174,6 @@ final class ClassRenamer
if (!$this->isClassToInterfaceValidChange($fullyQualified, $newName)) {
return null;
}
// no need to preslash "use \SomeNamespace" of imported namespace
if ($fullyQualified->getAttribute(AttributeKey::IS_USEUSE_NAME) === \true) {
// no need to rename imports, they will be handled by autoimport and coding standard
// also they might cause some rename
return null;
}
if ($this->shouldSkip($newName, $fullyQualified)) {
return null;
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '863a5ed69a150aed2c87038ef35421ee1626abd3';
public const PACKAGE_VERSION = '76714b95f240409a6fad92725ea19c870ed3ff14';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-01-17 18:37:42';
public const RELEASE_DATE = '2024-01-18 21:39:30';
/**
* @var int
*/

View File

@ -205,10 +205,6 @@ final class AttributeKey
* @var string
*/
public const IS_ARRAY_IN_ATTRIBUTE = 'is_array_in_attribute';
/**
* @var string
*/
public const IS_USEUSE_NAME = 'is_useuse_name';
/**
* @var string
*/

View File

@ -9,8 +9,6 @@ use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Use_;
use PhpParser\Node\Stmt\UseUse;
use PhpParser\NodeVisitorAbstract;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface;
@ -18,10 +16,6 @@ final class NameNodeVisitor extends NodeVisitorAbstract implements ScopeResolver
{
public function enterNode(Node $node) : ?Node
{
if ($node instanceof UseUse && ($node->type === Use_::TYPE_NORMAL || $node->type === Use_::TYPE_UNKNOWN)) {
$node->name->setAttribute(AttributeKey::IS_USEUSE_NAME, \true);
return null;
}
if ($node instanceof FuncCall && $node->name instanceof Name) {
$node->name->setAttribute(AttributeKey::IS_FUNCCALL_NAME, \true);
return null;

View File

@ -12,8 +12,6 @@ use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Expr\Yield_;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Param;
use PhpParser\Node\Scalar\DNumber;
use PhpParser\Node\Scalar\EncapsedStringPart;
@ -23,7 +21,6 @@ use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Declare_;
use PhpParser\Node\Stmt\Nop;
use PhpParser\Node\Stmt\Use_;
use PhpParser\PrettyPrinter\Standard;
use PHPStan\Node\Expr\AlwaysRememberedExpr;
use Rector\Configuration\Option;
@ -303,22 +300,6 @@ final class BetterStandardPrinter extends Standard
}
return parent::pExpr_Ternary($ternary);
}
/**
* Remove extra \\ from FQN use imports, for easier use in the code
*/
protected function pStmt_Use(Use_ $use) : string
{
if ($use->type !== Use_::TYPE_NORMAL) {
return parent::pStmt_Use($use);
}
foreach ($use->uses as $useUse) {
if (!$useUse->name instanceof FullyQualified) {
continue;
}
$useUse->name = new Name($useUse->name->toString());
}
return parent::pStmt_Use($use);
}
protected function pScalar_EncapsedStringPart(EncapsedStringPart $encapsedStringPart) : string
{
// parent throws exception, but we need to compare string

View File

@ -9,7 +9,6 @@ use PhpParser\Node\Stmt\UseUse;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeWithClassName;
use Rector\NodeTypeResolver\Node\AttributeKey;
/**
* @api
*/
@ -35,7 +34,6 @@ final class AliasedObjectType extends ObjectType
public function getUseNode(int $useType) : Use_
{
$name = new Name($this->fullyQualifiedClass);
$name->setAttribute(AttributeKey::IS_USEUSE_NAME, \true);
$useUse = new UseUse($name, $this->getClassName());
$use = new Use_([$useUse]);
$use->type = $useType;

View File

@ -48,7 +48,6 @@ final class FullyQualifiedObjectType extends ObjectType
public function getUseNode(int $useType) : Use_
{
$name = new Name($this->getClassName());
$name->setAttribute(AttributeKey::IS_USEUSE_NAME, \true);
$useUse = new UseUse($name);
$use = new Use_([$useUse]);
$use->type = $useType;

View File

@ -1866,12 +1866,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "77a7efb5074ed617d9a45b3988eff8e61e0c284b"
"reference": "6302080a5c701da9260970739ec68b1cb4ad5edb"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/77a7efb5074ed617d9a45b3988eff8e61e0c284b",
"reference": "77a7efb5074ed617d9a45b3988eff8e61e0c284b",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/6302080a5c701da9260970739ec68b1cb4ad5edb",
"reference": "6302080a5c701da9260970739ec68b1cb4ad5edb",
"shasum": ""
},
"require": {
@ -1900,7 +1900,7 @@
"tomasvotruba\/class-leak": "^0.2.6",
"tracy\/tracy": "^2.10"
},
"time": "2024-01-18T08:21:52+00:00",
"time": "2024-01-18T08:47:34+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main b419ce7'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 51ff6e7'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main f091938'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 77a7efb'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main b419ce7'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 51ff6e7'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main f091938'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 6302080'));
private function __construct()
{
}

View File

@ -25,6 +25,7 @@ use Rector\Symfony\Utils\StringUtils;
use Rector\Symfony\ValueObject\ExtensionKeyAndConfiguration;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use RectorPrefix202401\Webmozart\Assert\Assert;
/**
* @changelog https://symfony.com/blog/new-in-symfony-5-3-config-builder-classes
*
@ -70,7 +71,7 @@ final class StringExtensionToConfigBuilderRector extends AbstractRector
/**
* @var array<string, string>
*/
private const EXTENSION_KEY_TO_CLASS_MAP = ['security' => 'Symfony\\Config\\SecurityConfig', 'framework' => 'Symfony\\Config\\FrameworkConfig', 'monolog' => 'Symfony\\Config\\MonologConfig', 'twig' => 'Symfony\\Config\\TwigConfig', 'doctrine' => 'Symfony\\Config\\DoctrineConfig', 'doctrine_migrations' => 'Symfony\\Config\\DoctrineMigrationsConfig', 'sentry' => 'Symfony\\Config\\DoctrineMigrationsConfig'];
private const EXTENSION_KEY_TO_CLASS_MAP = ['security' => 'Symfony\\Config\\SecurityConfig', 'framework' => 'Symfony\\Config\\FrameworkConfig', 'monolog' => 'Symfony\\Config\\MonologConfig', 'twig' => 'Symfony\\Config\\TwigConfig', 'doctrine' => 'Symfony\\Config\\DoctrineConfig', 'doctrine_migrations' => 'Symfony\\Config\\DoctrineMigrationsConfig', 'sentry' => 'Symfony\\Config\\SentryConfig'];
public function __construct(SymfonyPhpClosureDetector $symfonyPhpClosureDetector, SymfonyClosureExtensionMatcher $symfonyClosureExtensionMatcher, PropertyNaming $propertyNaming, ValueResolver $valueResolver, NestedConfigCallsFactory $nestedConfigCallsFactory, SecurityAccessDecisionManagerConfigArrayHandler $securityAccessDecisionManagerConfigArrayHandler, SymfonyClosureFactory $symfonyClosureFactory)
{
$this->symfonyPhpClosureDetector = $symfonyPhpClosureDetector;
@ -123,13 +124,16 @@ CODE_SAMPLE
if (!$this->symfonyPhpClosureDetector->detect($node)) {
return null;
}
// make sure to avoid duplicates
Assert::uniqueValues(self::EXTENSION_KEY_TO_CLASS_MAP);
Assert::uniqueValues(\array_keys(self::EXTENSION_KEY_TO_CLASS_MAP));
$extensionKeyAndConfiguration = $this->symfonyClosureExtensionMatcher->match($node);
if (!$extensionKeyAndConfiguration instanceof ExtensionKeyAndConfiguration) {
return null;
}
$configClass = self::EXTENSION_KEY_TO_CLASS_MAP[$extensionKeyAndConfiguration->getKey()] ?? null;
if ($configClass === null) {
throw new NotImplementedYetException($extensionKeyAndConfiguration->getKey());
throw new NotImplementedYetException(\sprintf('The extensions "%s" is not supported yet. Check the rule and add keyword.', $extensionKeyAndConfiguration->getKey()));
}
$configVariable = $this->createConfigVariable($configClass);
$stmts = $this->createMethodCallStmts($extensionKeyAndConfiguration->getArray(), $configVariable);
@ -197,9 +201,14 @@ CODE_SAMPLE
continue;
}
$simpleMethodName = StringUtils::underscoreToCamelCase($key);
$args = $this->nodeFactory->createArgs([$value]);
$methodCall = new MethodCall($configVariable, $simpleMethodName, $args);
$methodCallStmts[] = new Expression($methodCall);
if (\is_array($value)) {
$simpleMethodCallStmts = $this->nestedConfigCallsFactory->create([$value], $configVariable, $simpleMethodName);
$methodCallStmts = \array_merge($methodCallStmts, $simpleMethodCallStmts);
} else {
$args = $this->nodeFactory->createArgs([$value]);
$methodCall = new MethodCall($configVariable, $simpleMethodName, $args);
$methodCallStmts[] = new Expression($methodCall);
}
}
}
return $methodCallStmts;