From 253b752428be8a1dcb623f20c0c805a5c0cd4281 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 26 Jun 2024 10:04:52 +0000 Subject: [PATCH] Updated Rector to commit 23597c551da3bd1f1477f4415b1b2cad4651307c https://github.com/rectorphp/rector-src/commit/23597c551da3bd1f1477f4415b1b2cad4651307c [Cleanup] Deprecate UseIncrementAssignRector as depends on context and might be intentional (#6042) --- config/set/rector-preset.php | 3 +- docs/rector_rules_overview.md | 102 +++++++++--------- .../SimplifyUselessVariableRector.php | 12 ++- .../Rector/Plus/UseIncrementAssignRector.php | 2 +- src/Application/VersionResolver.php | 4 +- 5 files changed, 63 insertions(+), 60 deletions(-) diff --git a/config/set/rector-preset.php b/config/set/rector-preset.php index ca10869c848..fd04f4b60ef 100644 --- a/config/set/rector-preset.php +++ b/config/set/rector-preset.php @@ -7,11 +7,10 @@ use Rector\CodeQuality\Rector\FuncCall\BoolvalToTypeCastRector; use Rector\CodeQuality\Rector\FuncCall\FloatvalToTypeCastRector; use Rector\CodeQuality\Rector\FuncCall\IntvalToTypeCastRector; use Rector\CodeQuality\Rector\FuncCall\StrvalToTypeCastRector; -use Rector\CodingStyle\Rector\Plus\UseIncrementAssignRector; use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector; use Rector\Config\RectorConfig; use Rector\Privatization\Rector\Class_\FinalizeTestCaseClassRector; use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector; return static function (RectorConfig $rectorConfig) : void { - $rectorConfig->rules([DeclareStrictTypesRector::class, IntvalToTypeCastRector::class, StrvalToTypeCastRector::class, BoolvalToTypeCastRector::class, FloatvalToTypeCastRector::class, PostIncDecToPreIncDecRector::class, UseIncrementAssignRector::class, FinalizeTestCaseClassRector::class]); + $rectorConfig->rules([DeclareStrictTypesRector::class, IntvalToTypeCastRector::class, StrvalToTypeCastRector::class, BoolvalToTypeCastRector::class, FloatvalToTypeCastRector::class, PostIncDecToPreIncDecRector::class, FinalizeTestCaseClassRector::class]); }; diff --git a/docs/rector_rules_overview.md b/docs/rector_rules_overview.md index a2f4eb39105..8d5eccaaef4 100644 --- a/docs/rector_rules_overview.md +++ b/docs/rector_rules_overview.md @@ -10,11 +10,11 @@ - [CodeQuality](#codequality) (73) -- [CodingStyle](#codingstyle) (28) +- [CodingStyle](#codingstyle) (27) - [DeadCode](#deadcode) (45) -- [EarlyReturn](#earlyreturn) (9) +- [EarlyReturn](#earlyreturn) (8) - [Instanceof](#instanceof) (1) @@ -60,7 +60,7 @@ - [Transform](#transform) (25) -- [TypeDeclaration](#typedeclaration) (50) +- [TypeDeclaration](#typedeclaration) (52) - [Visibility](#visibility) (3) @@ -1354,6 +1354,8 @@ Simplify tautology ternary to value Removes useless variable assigns +:wrench: **configure it!** + - class: [`Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector`](../rules/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector.php) ```diff @@ -1366,6 +1368,18 @@ Removes useless variable assigns
+```diff + function () { + $a = 'Hello, '; +- $a .= 'World!'; + +- return $a; ++ return $a . 'World!'; + }; +``` + +
+ ### SingleInArrayToCompareRector Changes `in_array()` with single element to === @@ -2141,25 +2155,6 @@ Use `class` keyword for class name resolution in string instead of hardcoded str
-### UseIncrementAssignRector - -Use ++ increment instead of `$var += 1` - -- class: [`Rector\CodingStyle\Rector\Plus\UseIncrementAssignRector`](../rules/CodingStyle/Rector/Plus/UseIncrementAssignRector.php) - -```diff - class SomeClass - { - public function run() - { -- $style += 1; -+ ++$style; - } - } -``` - -
- ### VersionCompareFuncCallToConstantRector Changes use of call to version compare function to use of PHP version constant @@ -3111,35 +3106,6 @@ Remove php version checks if they are passed ## EarlyReturn -### ChangeAndIfToEarlyReturnRector - -Changes if && to early return - -- class: [`Rector\EarlyReturn\Rector\If_\ChangeAndIfToEarlyReturnRector`](../rules/EarlyReturn/Rector/If_/ChangeAndIfToEarlyReturnRector.php) - -```diff - class SomeClass - { - public function canDrive(Car $car) - { -- if ($car->hasWheels && $car->hasFuel) { -- return true; -+ if (! $car->hasWheels) { -+ return false; - } - -- return false; -+ if (! $car->hasFuel) { -+ return false; -+ } -+ -+ return true; - } - } -``` - -
- ### ChangeIfElseValueAssignToEarlyReturnRector Change if/else value to early return @@ -6500,6 +6466,40 @@ Add known return type to arrow function
+### AddClosureNeverReturnTypeRector + +Add "never" return-type for closure that never return anything + +- class: [`Rector\TypeDeclaration\Rector\Closure\AddClosureNeverReturnTypeRector`](../rules/TypeDeclaration/Rector/Closure/AddClosureNeverReturnTypeRector.php) + +```diff +-function () { ++function (): never { + throw new InvalidException(); + } +``` + +
+ +### AddClosureUnionReturnTypeRector + +Add union return type on closure + +- class: [`Rector\TypeDeclaration\Rector\Closure\AddClosureUnionReturnTypeRector`](../rules/TypeDeclaration/Rector/Closure/AddClosureUnionReturnTypeRector.php) + +```diff +-function () { ++function (): int|string { + if (rand(0, 1)) { + return 1; + } + + return 'one'; + } +``` + +
+ ### AddClosureVoidReturnTypeWhereNoReturnRector Add closure return type void if there is no return diff --git a/rules/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector.php b/rules/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector.php index 78fd46d337c..e755d08e019 100644 --- a/rules/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector.php +++ b/rules/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector.php @@ -20,7 +20,6 @@ use Rector\NodeAnalyzer\VariableAnalyzer; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\PhpParser\Node\AssignAndBinaryMap; use Rector\Rector\AbstractRector; -use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** @@ -70,18 +69,23 @@ final class SimplifyUselessVariableRector extends AbstractRector implements Conf } public function getRuleDefinition() : RuleDefinition { - return new RuleDefinition('Removes useless variable assigns', [new CodeSample(<<<'CODE_SAMPLE' + return new RuleDefinition('Removes useless variable assigns', [new ConfiguredCodeSample( + <<<'CODE_SAMPLE' function () { $a = true; return $a; }; CODE_SAMPLE -, <<<'CODE_SAMPLE' +, + <<<'CODE_SAMPLE' function () { return true; }; CODE_SAMPLE -), new ConfiguredCodeSample(<<<'CODE_SAMPLE' +, + // default + [self::ONLY_DIRECT_ASSIGN => \true] + ), new ConfiguredCodeSample(<<<'CODE_SAMPLE' function () { $a = 'Hello, '; $a .= 'World!'; diff --git a/rules/CodingStyle/Rector/Plus/UseIncrementAssignRector.php b/rules/CodingStyle/Rector/Plus/UseIncrementAssignRector.php index 7f1fef57298..f89dbc915c9 100644 --- a/rules/CodingStyle/Rector/Plus/UseIncrementAssignRector.php +++ b/rules/CodingStyle/Rector/Plus/UseIncrementAssignRector.php @@ -13,7 +13,7 @@ use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** - * @see \Rector\Tests\CodingStyle\Rector\Plus\UseIncrementAssignRector\UseIncrementAssignRectorTest + * @deprecated Since 1.1.2 as often used intentionally and depends on context. Cannot be changed in one way. */ final class UseIncrementAssignRector extends AbstractRector { diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 2fb5706a029..bbea34d9e4c 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'd68e8fa32a27c1ddd474ef6f1b4e1f63a74e5708'; + public const PACKAGE_VERSION = '23597c551da3bd1f1477f4415b1b2cad4651307c'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-06-26 11:07:18'; + public const RELEASE_DATE = '2024-06-26 12:02:15'; /** * @var int */