Skip to content

Commit

Permalink
[Transform] Remove CallableInMethodCallToVariableRector as very narro…
Browse files Browse the repository at this point in the history
…w use case and sensitive to wrong change (#2625)
  • Loading branch information
TomasVotruba committed Jul 3, 2022
1 parent f78af10 commit 646d188
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 424 deletions.
75 changes: 3 additions & 72 deletions build/target-repository/docs/rector_rules_overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 412 Rules Overview
# 411 Rules Overview

<br>

Expand All @@ -20,7 +20,7 @@

- [DogFood](#dogfood) (1)

- [EarlyReturn](#earlyreturn) (12)
- [EarlyReturn](#earlyreturn) (11)

- [MysqlToMysqli](#mysqltomysqli) (4)

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

- [Strict](#strict) (5)

- [Transform](#transform) (36)
- [Transform](#transform) (35)

- [TypeDeclaration](#typedeclaration) (29)

Expand Down Expand Up @@ -4105,35 +4105,6 @@ Split if statement, when if condition always break execution flow

<br>

### ReturnAfterToEarlyOnBreakRector

Change return after foreach to early return in foreach on break

- class: [`Rector\EarlyReturn\Rector\Foreach_\ReturnAfterToEarlyOnBreakRector`](../rules/EarlyReturn/Rector/Foreach_/ReturnAfterToEarlyOnBreakRector.php)

```diff
class SomeClass
{
public function run(array $pathConstants, string $allowedPath)
{
- $pathOK = false;
-
foreach ($pathConstants as $allowedPath) {
if ($dirPath == $allowedPath) {
- $pathOK = true;
- break;
+ return true;
}
}

- return $pathOK;
+ return false;
}
}
```

<br>

### ReturnBinaryAndToEarlyReturnRector

Changes Single return of && to early returns
Expand Down Expand Up @@ -7947,46 +7918,6 @@ return static function (RectorConfig $rectorConfig): void {

<br>

### CallableInMethodCallToVariableRector

Change a callable in method call to standalone variable assign

:wrench: **configure it!**

- class: [`Rector\Transform\Rector\MethodCall\CallableInMethodCallToVariableRector`](../rules/Transform/Rector/MethodCall/CallableInMethodCallToVariableRector.php)

```php
use Rector\Config\RectorConfig;
use Rector\Transform\Rector\MethodCall\CallableInMethodCallToVariableRector;
use Rector\Transform\ValueObject\CallableInMethodCallToVariable;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(
CallableInMethodCallToVariableRector::class,
[new CallableInMethodCallToVariable('Nette\Caching\Cache', 'save', 1)]
);
};
```


```diff
final class SomeClass
{
public function run()
{
/** @var \Nette\Caching\Cache $cache */
- $cache->save($key, function () use ($container) {
- return 100;
- });
+ $result = 100;
+ $cache->save($key, $result);
}
}
```

<br>

### ChangeSingletonToServiceRector

Change singleton class to normal class that can be registered as a service
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

40 changes: 0 additions & 40 deletions rules/Transform/NodeFactory/UnwrapClosureFactory.php

This file was deleted.

Loading

0 comments on commit 646d188

Please sign in to comment.