Skip to content

Commit

Permalink
[Cleanup] Deprecate UseIncrementAssignRector as depends on context an…
Browse files Browse the repository at this point in the history
…d might be intentional (#6042)

* [Cleanup] Deprecate UseIncrementAssignRector as depends on context and might be intentional

* fix doc sample to pass
  • Loading branch information
TomasVotruba committed Jun 26, 2024
1 parent d68e8fa commit 23597c5
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 128 deletions.
102 changes: 51 additions & 51 deletions build/target-repository/docs/rector_rules_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -60,7 +60,7 @@

- [Transform](#transform) (25)

- [TypeDeclaration](#typedeclaration) (50)
- [TypeDeclaration](#typedeclaration) (52)

- [Visibility](#visibility) (3)

Expand Down Expand Up @@ -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
Expand All @@ -1366,6 +1368,18 @@ Removes useless variable assigns

<br>

```diff
function () {
$a = 'Hello, ';
- $a .= 'World!';

- return $a;
+ return $a . 'World!';
};
```

<br>

### SingleInArrayToCompareRector

Changes `in_array()` with single element to ===
Expand Down Expand Up @@ -2141,25 +2155,6 @@ Use `class` keyword for class name resolution in string instead of hardcoded str

<br>

### 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;
}
}
```

<br>

### VersionCompareFuncCallToConstantRector

Changes use of call to version compare function to use of PHP version constant
Expand Down Expand Up @@ -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;
}
}
```

<br>

### ChangeIfElseValueAssignToEarlyReturnRector

Change if/else value to early return
Expand Down Expand Up @@ -6500,6 +6466,40 @@ Add known return type to arrow function

<br>

### 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();
}
```

<br>

### 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';
}
```

<br>

### AddClosureVoidReturnTypeWhereNoReturnRector

Add closure return type void if there is no return
Expand Down
2 changes: 0 additions & 2 deletions config/set/rector-preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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;
Expand All @@ -20,7 +19,6 @@
BoolvalToTypeCastRector::class,
FloatvalToTypeCastRector::class,
PostIncDecToPreIncDecRector::class,
UseIncrementAssignRector::class,
FinalizeTestCaseClassRector::class,
]);
};

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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;

Expand Down Expand Up @@ -54,7 +53,7 @@ public function configure(array $configuration): void
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Removes useless variable assigns', [
new CodeSample(
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
function () {
$a = true;
Expand All @@ -67,6 +66,11 @@ function () {
return true;
};
CODE_SAMPLE
,
// default
[
self::ONLY_DIRECT_ASSIGN => true,
]
),
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
Expand Down
2 changes: 1 addition & 1 deletion rules/CodingStyle/Rector/Plus/UseIncrementAssignRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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
{
Expand Down

0 comments on commit 23597c5

Please sign in to comment.