mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
Updated Rector to commit 6646d23fe0cea4b4a871ca1931e33f0cb2a574c7
6646d23fe0
[CodingStyle] Add RemoveUselessAliasInUseStatementRector (#5394)
This commit is contained in:
parent
801e9accb8
commit
95ed962a15
@ -26,6 +26,7 @@ use Rector\CodingStyle\Rector\Plus\UseIncrementAssignRector;
|
||||
use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
|
||||
use Rector\CodingStyle\Rector\Property\SplitGroupedPropertiesRector;
|
||||
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
|
||||
use Rector\CodingStyle\Rector\Stmt\RemoveUselessAliasInUseStatementRector;
|
||||
use Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector;
|
||||
use Rector\CodingStyle\Rector\String_\UseClassKeywordForClassNameResolutionRector;
|
||||
use Rector\CodingStyle\Rector\Ternary\TernaryConditionVariableAssignmentRector;
|
||||
@ -36,5 +37,5 @@ use Rector\Transform\Rector\FuncCall\FuncCallToConstFetchRector;
|
||||
use Rector\Visibility\Rector\ClassMethod\ExplicitPublicClassMethodRector;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->ruleWithConfiguration(FuncCallToConstFetchRector::class, ['php_sapi_name' => 'PHP_SAPI', 'pi' => 'M_PI']);
|
||||
$rectorConfig->rules([SeparateMultiUseImportsRector::class, PostIncDecToPreIncDecRector::class, NewlineAfterStatementRector::class, RemoveFinalFromConstRector::class, NullableCompareToNullRector::class, ConsistentImplodeRector::class, TernaryConditionVariableAssignmentRector::class, SymplifyQuoteEscapeRector::class, StringClassNameToClassConstantRector::class, CatchExceptionNameMatchingTypeRector::class, UseIncrementAssignRector::class, SplitDoubleAssignRector::class, EncapsedStringsToSprintfRector::class, WrapEncapsedVariableInCurlyBracesRector::class, NewlineBeforeNewAssignSetRector::class, MakeInheritedMethodVisibilitySameAsParentRector::class, CallUserFuncArrayToVariadicRector::class, VersionCompareFuncCallToConstantRector::class, StaticArrowFunctionRector::class, StaticClosureRector::class, CountArrayToEmptyArrayComparisonRector::class, CallUserFuncToMethodCallRector::class, FuncGetArgsToVariadicParamRector::class, StrictArraySearchRector::class, UseClassKeywordForClassNameResolutionRector::class, SplitGroupedPropertiesRector::class, SplitGroupedClassConstantsRector::class, ExplicitPublicClassMethodRector::class, ArraySpreadInsteadOfArrayMergeRector::class]);
|
||||
$rectorConfig->rules([SeparateMultiUseImportsRector::class, PostIncDecToPreIncDecRector::class, NewlineAfterStatementRector::class, RemoveFinalFromConstRector::class, NullableCompareToNullRector::class, ConsistentImplodeRector::class, TernaryConditionVariableAssignmentRector::class, SymplifyQuoteEscapeRector::class, StringClassNameToClassConstantRector::class, CatchExceptionNameMatchingTypeRector::class, UseIncrementAssignRector::class, SplitDoubleAssignRector::class, EncapsedStringsToSprintfRector::class, WrapEncapsedVariableInCurlyBracesRector::class, NewlineBeforeNewAssignSetRector::class, MakeInheritedMethodVisibilitySameAsParentRector::class, CallUserFuncArrayToVariadicRector::class, VersionCompareFuncCallToConstantRector::class, StaticArrowFunctionRector::class, StaticClosureRector::class, CountArrayToEmptyArrayComparisonRector::class, CallUserFuncToMethodCallRector::class, FuncGetArgsToVariadicParamRector::class, StrictArraySearchRector::class, UseClassKeywordForClassNameResolutionRector::class, SplitGroupedPropertiesRector::class, SplitGroupedClassConstantsRector::class, ExplicitPublicClassMethodRector::class, ArraySpreadInsteadOfArrayMergeRector::class, RemoveUselessAliasInUseStatementRector::class]);
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
# 353 Rules Overview
|
||||
# 354 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
- [CodeQuality](#codequality) (73)
|
||||
|
||||
- [CodingStyle](#codingstyle) (27)
|
||||
- [CodingStyle](#codingstyle) (28)
|
||||
|
||||
- [DeadCode](#deadcode) (43)
|
||||
|
||||
@ -1867,6 +1867,19 @@ Remove final from constants in classes defined as final
|
||||
|
||||
<br>
|
||||
|
||||
### RemoveUselessAliasInUseStatementRector
|
||||
|
||||
Remove useless alias in use statement as same name with last use statement name
|
||||
|
||||
- class: [`Rector\CodingStyle\Rector\Stmt\RemoveUselessAliasInUseStatementRector`](../rules/CodingStyle/Rector/Stmt/RemoveUselessAliasInUseStatementRector.php)
|
||||
|
||||
```diff
|
||||
-use App\Bar as Bar;
|
||||
+use App\Bar;
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### SeparateMultiUseImportsRector
|
||||
|
||||
Split multi use imports and trait statements to standalone lines
|
||||
@ -4765,13 +4778,13 @@ Change simple property init and assign to constructor promotion
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public float $someVariable;
|
||||
- public float $price;
|
||||
-
|
||||
public function __construct(
|
||||
- float $someVariable = 0.0
|
||||
+ public float $someVariable = 0.0
|
||||
- float $price = 0.0
|
||||
+ public float $price = 0.0
|
||||
) {
|
||||
- $this->someVariable = $someVariable;
|
||||
- $this->price = $price;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\CodingStyle\Rector\Stmt;
|
||||
|
||||
use RectorPrefix202312\Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Stmt\Namespace_;
|
||||
use PhpParser\Node\Stmt\Use_;
|
||||
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\CodingStyle\Rector\Stmt\RemoveUselessAliasInUseStatementRector\RemoveUselessAliasInUseStatementRectorTest
|
||||
*/
|
||||
final class RemoveUselessAliasInUseStatementRector extends AbstractRector
|
||||
{
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Remove useless alias in use statement as same name with last use statement name', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
use App\Bar as Bar;
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
use App\Bar;
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [FileWithoutNamespace::class, Namespace_::class];
|
||||
}
|
||||
/**
|
||||
* @param FileWithoutNamespace|Namespace_ $node
|
||||
* @return null|\Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace|\PhpParser\Node\Stmt\Namespace_
|
||||
*/
|
||||
public function refactor(Node $node)
|
||||
{
|
||||
$hasChanged = \false;
|
||||
foreach ($node->stmts as $stmt) {
|
||||
if (!$stmt instanceof Use_) {
|
||||
continue;
|
||||
}
|
||||
if (\count($stmt->uses) !== 1) {
|
||||
continue;
|
||||
}
|
||||
if (!isset($stmt->uses[0])) {
|
||||
continue;
|
||||
}
|
||||
$aliasName = $stmt->uses[0]->alias instanceof Identifier ? $stmt->uses[0]->alias->toString() : null;
|
||||
if ($aliasName === null) {
|
||||
continue;
|
||||
}
|
||||
$useName = $stmt->uses[0]->name->toString();
|
||||
$lastName = Strings::after($useName, '\\', -1) ?? $useName;
|
||||
if ($lastName === $aliasName) {
|
||||
$stmt->uses[0]->alias = null;
|
||||
$hasChanged = \true;
|
||||
}
|
||||
}
|
||||
if ($hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '6bff51172cf396da8abc062d96f0406fd86ef349';
|
||||
public const PACKAGE_VERSION = '6646d23fe0cea4b4a871ca1931e33f0cb2a574c7';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-12-25 10:15:01';
|
||||
public const RELEASE_DATE = '2023-12-26 18:37:51';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -1150,6 +1150,7 @@ return array(
|
||||
'Rector\\CodingStyle\\Rector\\PostInc\\PostIncDecToPreIncDecRector' => $baseDir . '/rules/CodingStyle/Rector/PostInc/PostIncDecToPreIncDecRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Property\\SplitGroupedPropertiesRector' => $baseDir . '/rules/CodingStyle/Rector/Property/SplitGroupedPropertiesRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Stmt\\NewlineAfterStatementRector' => $baseDir . '/rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Stmt\\RemoveUselessAliasInUseStatementRector' => $baseDir . '/rules/CodingStyle/Rector/Stmt/RemoveUselessAliasInUseStatementRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\String_\\SymplifyQuoteEscapeRector' => $baseDir . '/rules/CodingStyle/Rector/String_/SymplifyQuoteEscapeRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\String_\\UseClassKeywordForClassNameResolutionRector' => $baseDir . '/rules/CodingStyle/Rector/String_/UseClassKeywordForClassNameResolutionRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Ternary\\TernaryConditionVariableAssignmentRector' => $baseDir . '/rules/CodingStyle/Rector/Ternary/TernaryConditionVariableAssignmentRector.php',
|
||||
|
1
vendor/composer/autoload_static.php
vendored
1
vendor/composer/autoload_static.php
vendored
@ -1368,6 +1368,7 @@ class ComposerStaticInit8339caf294dd12447c06647e5d0dc118
|
||||
'Rector\\CodingStyle\\Rector\\PostInc\\PostIncDecToPreIncDecRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/PostInc/PostIncDecToPreIncDecRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Property\\SplitGroupedPropertiesRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/Property/SplitGroupedPropertiesRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Stmt\\NewlineAfterStatementRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Stmt\\RemoveUselessAliasInUseStatementRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/Stmt/RemoveUselessAliasInUseStatementRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\String_\\SymplifyQuoteEscapeRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/String_/SymplifyQuoteEscapeRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\String_\\UseClassKeywordForClassNameResolutionRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/String_/UseClassKeywordForClassNameResolutionRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Ternary\\TernaryConditionVariableAssignmentRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/Ternary/TernaryConditionVariableAssignmentRector.php',
|
||||
|
Loading…
x
Reference in New Issue
Block a user