Skip to content

Commit

Permalink
Updated Rector to commit 76714b95f240409a6fad92725ea19c870ed3ff14
Browse files Browse the repository at this point in the history
rectorphp/rector-src@76714b9 [Printer] Remove unnecessary BetterStandardPrinter::pStmt_Use() (#5478)
  • Loading branch information
TomasVotruba committed Jan 18, 2024
1 parent 08a112c commit f605aeb
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 51 deletions.
6 changes: 0 additions & 6 deletions rules/Renaming/NodeManipulator/ClassRenamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,6 @@ private function refactorName(FullyQualified $fullyQualified, array $oldToNewCla
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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 0 additions & 4 deletions src/NodeTypeResolver/Node/AttributeKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,13 @@
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;
final class NameNodeVisitor extends NodeVisitorAbstract implements ScopeResolverNodeVisitorInterface
{
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;
Expand Down
19 changes: 0 additions & 19 deletions src/PhpParser/Printer/BetterStandardPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
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;
Expand All @@ -23,7 +21,6 @@
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;
Expand Down Expand Up @@ -303,22 +300,6 @@ protected function pExpr_Ternary(Ternary $ternary) : string
}
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
Expand Down
2 changes: 0 additions & 2 deletions src/StaticTypeMapper/ValueObject/Type/AliasedObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeWithClassName;
use Rector\NodeTypeResolver\Node\AttributeKey;
/**
* @api
*/
Expand All @@ -35,7 +34,6 @@ public function getFullyQualifiedName() : string
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function getShortNameNode() : Name
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;
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion vendor/composer/installed.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vendor/rector/extension-installer/src/GeneratedConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
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()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -123,13 +124,16 @@ public function refactor(Node $node) : ?Node
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);
Expand Down Expand Up @@ -197,9 +201,14 @@ private function createMethodCallStmts(Array_ $configurationArray, Variable $con
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;
Expand Down

0 comments on commit f605aeb

Please sign in to comment.