Skip to content

Commit f605aeb

Browse files
committed
Updated Rector to commit 76714b95f240409a6fad92725ea19c870ed3ff14
rectorphp/rector-src@76714b9 [Printer] Remove unnecessary BetterStandardPrinter::pStmt_Use() (#5478)
1 parent 08a112c commit f605aeb

File tree

11 files changed

+22
-51
lines changed

11 files changed

+22
-51
lines changed

rules/Renaming/NodeManipulator/ClassRenamer.php

-6
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,6 @@ private function refactorName(FullyQualified $fullyQualified, array $oldToNewCla
174174
if (!$this->isClassToInterfaceValidChange($fullyQualified, $newName)) {
175175
return null;
176176
}
177-
// no need to preslash "use \SomeNamespace" of imported namespace
178-
if ($fullyQualified->getAttribute(AttributeKey::IS_USEUSE_NAME) === \true) {
179-
// no need to rename imports, they will be handled by autoimport and coding standard
180-
// also they might cause some rename
181-
return null;
182-
}
183177
if ($this->shouldSkip($newName, $fullyQualified)) {
184178
return null;
185179
}

src/Application/VersionResolver.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '863a5ed69a150aed2c87038ef35421ee1626abd3';
22+
public const PACKAGE_VERSION = '76714b95f240409a6fad92725ea19c870ed3ff14';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2024-01-17 18:37:42';
27+
public const RELEASE_DATE = '2024-01-18 21:39:30';
2828
/**
2929
* @var int
3030
*/

src/NodeTypeResolver/Node/AttributeKey.php

-4
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,6 @@ final class AttributeKey
205205
* @var string
206206
*/
207207
public const IS_ARRAY_IN_ATTRIBUTE = 'is_array_in_attribute';
208-
/**
209-
* @var string
210-
*/
211-
public const IS_USEUSE_NAME = 'is_useuse_name';
212208
/**
213209
* @var string
214210
*/

src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/NameNodeVisitor.php

-6
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,13 @@
99
use PhpParser\Node\Expr\New_;
1010
use PhpParser\Node\Expr\StaticCall;
1111
use PhpParser\Node\Name;
12-
use PhpParser\Node\Stmt\Use_;
13-
use PhpParser\Node\Stmt\UseUse;
1412
use PhpParser\NodeVisitorAbstract;
1513
use Rector\NodeTypeResolver\Node\AttributeKey;
1614
use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface;
1715
final class NameNodeVisitor extends NodeVisitorAbstract implements ScopeResolverNodeVisitorInterface
1816
{
1917
public function enterNode(Node $node) : ?Node
2018
{
21-
if ($node instanceof UseUse && ($node->type === Use_::TYPE_NORMAL || $node->type === Use_::TYPE_UNKNOWN)) {
22-
$node->name->setAttribute(AttributeKey::IS_USEUSE_NAME, \true);
23-
return null;
24-
}
2519
if ($node instanceof FuncCall && $node->name instanceof Name) {
2620
$node->name->setAttribute(AttributeKey::IS_FUNCCALL_NAME, \true);
2721
return null;

src/PhpParser/Printer/BetterStandardPrinter.php

-19
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
use PhpParser\Node\Expr\Closure;
1313
use PhpParser\Node\Expr\Ternary;
1414
use PhpParser\Node\Expr\Yield_;
15-
use PhpParser\Node\Name;
16-
use PhpParser\Node\Name\FullyQualified;
1715
use PhpParser\Node\Param;
1816
use PhpParser\Node\Scalar\DNumber;
1917
use PhpParser\Node\Scalar\EncapsedStringPart;
@@ -23,7 +21,6 @@
2321
use PhpParser\Node\Stmt\ClassMethod;
2422
use PhpParser\Node\Stmt\Declare_;
2523
use PhpParser\Node\Stmt\Nop;
26-
use PhpParser\Node\Stmt\Use_;
2724
use PhpParser\PrettyPrinter\Standard;
2825
use PHPStan\Node\Expr\AlwaysRememberedExpr;
2926
use Rector\Configuration\Option;
@@ -303,22 +300,6 @@ protected function pExpr_Ternary(Ternary $ternary) : string
303300
}
304301
return parent::pExpr_Ternary($ternary);
305302
}
306-
/**
307-
* Remove extra \\ from FQN use imports, for easier use in the code
308-
*/
309-
protected function pStmt_Use(Use_ $use) : string
310-
{
311-
if ($use->type !== Use_::TYPE_NORMAL) {
312-
return parent::pStmt_Use($use);
313-
}
314-
foreach ($use->uses as $useUse) {
315-
if (!$useUse->name instanceof FullyQualified) {
316-
continue;
317-
}
318-
$useUse->name = new Name($useUse->name->toString());
319-
}
320-
return parent::pStmt_Use($use);
321-
}
322303
protected function pScalar_EncapsedStringPart(EncapsedStringPart $encapsedStringPart) : string
323304
{
324305
// parent throws exception, but we need to compare string

src/StaticTypeMapper/ValueObject/Type/AliasedObjectType.php

-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PHPStan\Type\ObjectType;
1010
use PHPStan\Type\Type;
1111
use PHPStan\Type\TypeWithClassName;
12-
use Rector\NodeTypeResolver\Node\AttributeKey;
1312
/**
1413
* @api
1514
*/
@@ -35,7 +34,6 @@ public function getFullyQualifiedName() : string
3534
public function getUseNode(int $useType) : Use_
3635
{
3736
$name = new Name($this->fullyQualifiedClass);
38-
$name->setAttribute(AttributeKey::IS_USEUSE_NAME, \true);
3937
$useUse = new UseUse($name, $this->getClassName());
4038
$use = new Use_([$useUse]);
4139
$use->type = $useType;

src/StaticTypeMapper/ValueObject/Type/FullyQualifiedObjectType.php

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public function getShortNameNode() : Name
4848
public function getUseNode(int $useType) : Use_
4949
{
5050
$name = new Name($this->getClassName());
51-
$name->setAttribute(AttributeKey::IS_USEUSE_NAME, \true);
5251
$useUse = new UseUse($name);
5352
$use = new Use_([$useUse]);
5453
$use->type = $useType;

vendor/composer/installed.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1866,12 +1866,12 @@
18661866
"source": {
18671867
"type": "git",
18681868
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
1869-
"reference": "77a7efb5074ed617d9a45b3988eff8e61e0c284b"
1869+
"reference": "6302080a5c701da9260970739ec68b1cb4ad5edb"
18701870
},
18711871
"dist": {
18721872
"type": "zip",
1873-
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/77a7efb5074ed617d9a45b3988eff8e61e0c284b",
1874-
"reference": "77a7efb5074ed617d9a45b3988eff8e61e0c284b",
1873+
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/6302080a5c701da9260970739ec68b1cb4ad5edb",
1874+
"reference": "6302080a5c701da9260970739ec68b1cb4ad5edb",
18751875
"shasum": ""
18761876
},
18771877
"require": {
@@ -1900,7 +1900,7 @@
19001900
"tomasvotruba\/class-leak": "^0.2.6",
19011901
"tracy\/tracy": "^2.10"
19021902
},
1903-
"time": "2024-01-18T08:21:52+00:00",
1903+
"time": "2024-01-18T08:47:34+00:00",
19041904
"default-branch": true,
19051905
"type": "rector-extension",
19061906
"extra": {

vendor/composer/installed.php

+1-1
Large diffs are not rendered by default.

vendor/rector/extension-installer/src/GeneratedConfig.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
final class GeneratedConfig
1111
{
12-
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'));
12+
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'));
1313
private function __construct()
1414
{
1515
}

vendor/rector/rector-symfony/rules/CodeQuality/Rector/Closure/StringExtensionToConfigBuilderRector.php

+14-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Rector\Symfony\ValueObject\ExtensionKeyAndConfiguration;
2626
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
2727
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
28+
use RectorPrefix202401\Webmozart\Assert\Assert;
2829
/**
2930
* @changelog https://symfony.com/blog/new-in-symfony-5-3-config-builder-classes
3031
*
@@ -70,7 +71,7 @@ final class StringExtensionToConfigBuilderRector extends AbstractRector
7071
/**
7172
* @var array<string, string>
7273
*/
73-
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'];
74+
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'];
7475
public function __construct(SymfonyPhpClosureDetector $symfonyPhpClosureDetector, SymfonyClosureExtensionMatcher $symfonyClosureExtensionMatcher, PropertyNaming $propertyNaming, ValueResolver $valueResolver, NestedConfigCallsFactory $nestedConfigCallsFactory, SecurityAccessDecisionManagerConfigArrayHandler $securityAccessDecisionManagerConfigArrayHandler, SymfonyClosureFactory $symfonyClosureFactory)
7576
{
7677
$this->symfonyPhpClosureDetector = $symfonyPhpClosureDetector;
@@ -123,13 +124,16 @@ public function refactor(Node $node) : ?Node
123124
if (!$this->symfonyPhpClosureDetector->detect($node)) {
124125
return null;
125126
}
127+
// make sure to avoid duplicates
128+
Assert::uniqueValues(self::EXTENSION_KEY_TO_CLASS_MAP);
129+
Assert::uniqueValues(\array_keys(self::EXTENSION_KEY_TO_CLASS_MAP));
126130
$extensionKeyAndConfiguration = $this->symfonyClosureExtensionMatcher->match($node);
127131
if (!$extensionKeyAndConfiguration instanceof ExtensionKeyAndConfiguration) {
128132
return null;
129133
}
130134
$configClass = self::EXTENSION_KEY_TO_CLASS_MAP[$extensionKeyAndConfiguration->getKey()] ?? null;
131135
if ($configClass === null) {
132-
throw new NotImplementedYetException($extensionKeyAndConfiguration->getKey());
136+
throw new NotImplementedYetException(\sprintf('The extensions "%s" is not supported yet. Check the rule and add keyword.', $extensionKeyAndConfiguration->getKey()));
133137
}
134138
$configVariable = $this->createConfigVariable($configClass);
135139
$stmts = $this->createMethodCallStmts($extensionKeyAndConfiguration->getArray(), $configVariable);
@@ -197,9 +201,14 @@ private function createMethodCallStmts(Array_ $configurationArray, Variable $con
197201
continue;
198202
}
199203
$simpleMethodName = StringUtils::underscoreToCamelCase($key);
200-
$args = $this->nodeFactory->createArgs([$value]);
201-
$methodCall = new MethodCall($configVariable, $simpleMethodName, $args);
202-
$methodCallStmts[] = new Expression($methodCall);
204+
if (\is_array($value)) {
205+
$simpleMethodCallStmts = $this->nestedConfigCallsFactory->create([$value], $configVariable, $simpleMethodName);
206+
$methodCallStmts = \array_merge($methodCallStmts, $simpleMethodCallStmts);
207+
} else {
208+
$args = $this->nodeFactory->createArgs([$value]);
209+
$methodCall = new MethodCall($configVariable, $simpleMethodName, $args);
210+
$methodCallStmts[] = new Expression($methodCall);
211+
}
203212
}
204213
}
205214
return $methodCallStmts;

0 commit comments

Comments
 (0)