Skip to content

Commit

Permalink
Remove ToStringToMethodCallRector as not practical and only for demo,…
Browse files Browse the repository at this point in the history
… FalseReturnClassMethodToNullableRector, as requires detailed custom refactoring (#3854)

* add oustide any set

* enable explicit public rule

* Remove ToStringToMethodCallRector as not practical and only for demo

* Remove FalseReturnClassMethodToNullableRector, as requires detailed custom refactoring

* mics
  • Loading branch information
TomasVotruba committed May 15, 2023
1 parent 3df70bd commit c8f697b
Show file tree
Hide file tree
Showing 16 changed files with 6 additions and 597 deletions.
68 changes: 3 additions & 65 deletions build/target-repository/docs/rector_rules_overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 405 Rules Overview
# 403 Rules Overview

<br>

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

- [Strict](#strict) (6)

- [Transform](#transform) (30)
- [Transform](#transform) (29)

- [TypeDeclaration](#typedeclaration) (40)
- [TypeDeclaration](#typedeclaration) (39)

- [Visibility](#visibility) (3)

Expand Down Expand Up @@ -8617,41 +8617,6 @@ return static function (RectorConfig $rectorConfig): void {

<br>

### ToStringToMethodCallRector

Turns defined code uses of `"__toString()"` method to specific method calls.

:wrench: **configure it!**

- class: [`Rector\Transform\Rector\String_\ToStringToMethodCallRector`](../rules/Transform/Rector/String_/ToStringToMethodCallRector.php)

```php
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Transform\Rector\String_\ToStringToMethodCallRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(ToStringToMethodCallRector::class, [
'SomeObject' => 'getPath',
]);
};
```


```diff
$someValue = new SomeObject;
-$result = (string) $someValue;
-$result = $someValue->__toString();
+$result = $someValue->getPath();
+$result = $someValue->getPath();
```

<br>

### UnsetAndIssetToMethodCallRector

Turns defined `__isset`/`__unset` calls to specific method calls.
Expand Down Expand Up @@ -9139,33 +9104,6 @@ Change `empty()` on nullable object to instanceof check

<br>

### FalseReturnClassMethodToNullableRector

Change class method that returns false as invalid state, to nullable

- class: [`Rector\TypeDeclaration\Rector\ClassMethod\FalseReturnClassMethodToNullableRector`](../rules/TypeDeclaration/Rector/ClassMethod/FalseReturnClassMethodToNullableRector.php)

```diff
class SomeClass
{
- /**
- * @return false|int
- */
- public function run(int $number)
+ public function run(int $number): ?int
{
if ($number === 10) {
- return false;
+ return null;
}

return $number;
}
}
```

<br>

### FlipNegatedTernaryInstanceofRector

Flip negated ternary of instanceof to direct use of object
Expand Down
2 changes: 2 additions & 0 deletions config/set/coding-style.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use Rector\Config\RectorConfig;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Transform\Rector\FuncCall\FuncCallToConstFetchRector;
use Rector\Visibility\Rector\ClassMethod\ExplicitPublicClassMethodRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig
Expand Down Expand Up @@ -75,5 +76,6 @@
UseClassKeywordForClassNameResolutionRector::class,
SplitGroupedPropertiesRector::class,
SplitGroupedClassConstantsRector::class,
ExplicitPublicClassMethodRector::class,
]);
};
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,6 @@ parameters:
paths:
- src/DependencyInjection/DefinitionFinder.php

-
message: '#Parameter \#1 \$node of method Rector\\Core\\Rector\\AbstractRector\:\:getType\(\) expects PhpParser\\Node, PhpParser\\Node\\Expr\|null given#'
path: rules/TypeDeclaration/Rector/ClassMethod/FalseReturnClassMethodToNullableRector.php

# changelog generator
-
message: '#Do not use chained method calls\. Put each on separated lines#'
Expand Down
3 changes: 1 addition & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\ClassMethod\FalseReturnClassMethodToNullableRector;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;

return static function (RectorConfig $rectorConfig): void {
Expand All @@ -31,7 +30,7 @@
SetList::CODING_STYLE,
]);

$rectorConfig->rules([FalseReturnClassMethodToNullableRector::class, DeclareStrictTypesRector::class]);
$rectorConfig->rules([DeclareStrictTypesRector::class]);

$rectorConfig->ruleWithConfiguration(
PreferThisOrSelfMethodCallRector::class,
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.

This file was deleted.

0 comments on commit c8f697b

Please sign in to comment.