Skip to content

Commit

Permalink
[DX] Remove AddDefaultValueForUndefinedVariableRector as can generate…
Browse files Browse the repository at this point in the history
… broken code and depends on context (#4729)
  • Loading branch information
TomasVotruba committed Aug 9, 2023
1 parent 59cf4dd commit b93e285
Show file tree
Hide file tree
Showing 72 changed files with 26 additions and 2,419 deletions.
45 changes: 2 additions & 43 deletions build/target-repository/docs/rector_rules_overview.md
@@ -1,4 +1,4 @@
# 357 Rules Overview
# 356 Rules Overview

<br>

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

- [Php55](#php55) (6)

- [Php56](#php56) (2)
- [Php56](#php56) (1)

- [Php70](#php70) (19)

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

## Php56

### AddDefaultValueForUndefinedVariableRector

Adds default value for undefined variable

- class: [`Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector`](../rules/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php)

```diff
class SomeClass
{
public function run()
{
+ $a = null;
if (rand(0, 1)) {
$a = 5;
}
echo $a;
}
}
```

<br>

### PowToExpRector

Changes pow(val, val2) to ** (exp) parameter
Expand Down Expand Up @@ -7565,27 +7543,8 @@ return static function (RectorConfig $rectorConfig): void {

Add return type void to function like without any return

:wrench: **configure it!**

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

```php
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(AddVoidReturnTypeWhereNoReturnRector::class, [
AddVoidReturnTypeWhereNoReturnRector::USE_PHPDOC => false,
]);
};
```


```diff
final class SomeClass
{
Expand Down
4 changes: 0 additions & 4 deletions config/set/php56.php
Expand Up @@ -4,7 +4,6 @@

use Rector\Config\RectorConfig;
use Rector\Php56\Rector\FuncCall\PowToExpRector;
use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector;
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;

return static function (RectorConfig $rectorConfig): void {
Expand Down Expand Up @@ -48,7 +47,4 @@
'ocisetprefetch' => 'oci_set_prefetch',
'ocistatementtype' => 'oci_statement_type',
]);

# inspired by level in psalm - https://github.com/vimeo/psalm/blob/82e0bcafac723fdf5007a31a7ae74af1736c9f6f/tests/FileManipulationTest.php#L1063
$rectorConfig->rule(AddDefaultValueForUndefinedVariableRector::class);
};
39 changes: 20 additions & 19 deletions packages/Config/RectorConfig.php
Expand Up @@ -74,21 +74,6 @@ public function memoryLimit(string $memoryLimit): void
SimpleParameterProvider::setParameter(Option::MEMORY_LIMIT, $memoryLimit);
}

private function isRuleNoLongerExists(mixed $skipRule): bool
{
return
// only validate string
is_string($skipRule)
// not regex path
&& ! str_contains($skipRule, '*')
// not realpath
&& realpath($skipRule) === false
// a Rector end
&& str_ends_with($skipRule, 'Rector')
// class not exists
&& ! class_exists($skipRule);
}

/**
* @param array<int|string, mixed> $criteria
*/
Expand Down Expand Up @@ -126,10 +111,12 @@ public function skip(array $criteria): void
}

if ($notExistsRules !== []) {
throw new ShouldNotHappenException('Following skipped rules on $rectorConfig->skip() are no longer exists or changed to different namespace: ' . implode(
', ',
$notExistsRules
));
throw new ShouldNotHappenException(
'Following skipped rules on $rectorConfig->skip() are no longer exists or changed to different namespace: ' . implode(
', ',
$notExistsRules
)
);
}

SimpleParameterProvider::addParameter(Option::SKIP, $criteria);
Expand Down Expand Up @@ -309,6 +296,20 @@ public function indent(string $character, int $count): void
SimpleParameterProvider::setParameter(Option::INDENT_SIZE, $count);
}

private function isRuleNoLongerExists(mixed $skipRule): bool
{
return // only validate string
is_string($skipRule)
// not regex path
&& ! str_contains($skipRule, '*')
// not realpath
&& realpath($skipRule) === false
// a Rector end
&& str_ends_with($skipRule, 'Rector')
// class not exists
&& ! class_exists($skipRule);
}

/**
* @param string[] $values
* @return string[]
Expand Down
Expand Up @@ -4,8 +4,8 @@

namespace Rector\VendorLocker;

use PHPStan\BetterReflection\Reflection\ReflectionClass;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\BetterReflection\Reflection\ReflectionClass;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\Type;
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.

0 comments on commit b93e285

Please sign in to comment.