Skip to content

Commit

Permalink
[DX] Remove upgrade RectorConfig set, as last 2 version use only PHP (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Aug 29, 2022
1 parent bb59a7c commit 74f6b18
Show file tree
Hide file tree
Showing 29 changed files with 9 additions and 1,050 deletions.
2 changes: 1 addition & 1 deletion build/target-repository/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ By [buying a book](https://leanpub.com/rector-the-power-of-automated-refactoring

## Documentation

- [Explore 400+ Rector Rules](/docs/rector_rules_overview.md)
- [Explore Rector Rules](/docs/rector_rules_overview.md)
- [How to Ignore Rule or Paths](/docs/how_to_ignore_rule_or_paths.md)
- [Static Reflection and Autoload](/docs/static_reflection_and_autoload.md)
- [How to Configure Rule](/docs/how_to_configure_rules.md)
Expand Down
34 changes: 1 addition & 33 deletions build/target-repository/docs/rector_rules_overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 401 Rules Overview
# 400 Rules Overview

<br>

Expand All @@ -18,8 +18,6 @@

- [DependencyInjection](#dependencyinjection) (2)

- [DogFood](#dogfood) (1)

- [EarlyReturn](#earlyreturn) (11)

- [MysqlToMysqli](#mysqltomysqli) (4)
Expand Down Expand Up @@ -3773,36 +3771,6 @@ return static function (RectorConfig $rectorConfig): void {

<br>

## DogFood

### UpgradeRectorConfigRector

Upgrade rector.php config to use of RectorConfig

- class: [`Rector\DogFood\Rector\Closure\UpgradeRectorConfigRector`](../rules/DogFood/Rector/Closure/UpgradeRectorConfigRector.php)

```diff
-use Rector\Core\Configuration\Option;
use Rector\Php74\Rector\Property\TypedPropertyRector;
-use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
+use Rector\Config\RectorConfig;

-return static function (ContainerConfigurator $containerConfigurator): void {
- $parameters = $containerConfigurator->parameters();
- $parameters->set(Option::PARALLEL, true);
- $parameters->set(Option::AUTO_IMPORT_NAMES, true);
+return static function (RectorConfig $rectorConfig): void {
+ $rectorConfig->parallel();
+ $rectorConfig->importNames();

- $services = $containerConfigurator->services();
- $services->set(TypedPropertyRector::class);
+ $rectorConfig->rule(TypedPropertyRector::class);
};
```

<br>

## EarlyReturn

### ChangeAndIfToEarlyReturnRector
Expand Down
10 changes: 0 additions & 10 deletions config/set/rector-config.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,30 @@

namespace Rector\Defluent\NodeAnalyzer;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;

/**
* Utils for chain of MethodCall Node:
* "$this->methodCall()->chainedMethodCall()"
*/
final class FluentChainMethodCallNodeAnalyzer
{
public function __construct(
private readonly NodeNameResolver $nodeNameResolver,
) {
}

/**
* @return string[]
*/
public function collectMethodCallNamesInChain(MethodCall $desiredMethodCall): array
{
$methodCalls = $this->collectAllMethodCallsInChain($desiredMethodCall);

$methodNames = [];
foreach ($methodCalls as $methodCall) {
$methodName = $this->nodeNameResolver->getName($methodCall->name);
if ($methodName === null) {
continue;
}

$methodNames[] = $methodName;
}

return $methodNames;
}

/**
* @return MethodCall[]
*/
public function collectAllMethodCallsInChain(MethodCall $methodCall): array
public function resolveRootMethodCall(MethodCall $methodCall): ?MethodCall
{
$chainMethodCalls = [$methodCall];
$callerNode = $methodCall->var;

// traverse up
$currentNode = $methodCall->var;
while ($currentNode instanceof MethodCall) {
$chainMethodCalls[] = $currentNode;
$currentNode = $currentNode->var;
while ($callerNode instanceof MethodCall && $callerNode->var instanceof MethodCall) {
$callerNode = $callerNode->var;
}

// traverse down
if (count($chainMethodCalls) === 1) {
$currentNode = $methodCall->getAttribute(AttributeKey::PARENT_NODE);
while ($currentNode instanceof MethodCall) {
$chainMethodCalls[] = $currentNode;
$currentNode = $currentNode->getAttribute(AttributeKey::PARENT_NODE);
}
if ($callerNode instanceof MethodCall) {
return $callerNode;
}

return $chainMethodCalls;
return null;
}

public function resolveRootExpr(MethodCall $methodCall): Expr | Name
Expand All @@ -79,19 +40,4 @@ public function resolveRootExpr(MethodCall $methodCall): Expr | Name

return $callerNode;
}

public function resolveRootMethodCall(MethodCall $methodCall): ?MethodCall
{
$callerNode = $methodCall->var;

while ($callerNode instanceof MethodCall && $callerNode->var instanceof MethodCall) {
$callerNode = $callerNode->var;
}

if ($callerNode instanceof MethodCall) {
return $callerNode;
}

return null;
}
}
47 changes: 0 additions & 47 deletions packages/PhpDocParser/TypeAwareNodeFinder.php

This file was deleted.

15 changes: 0 additions & 15 deletions packages/PhpDocParser/ValueObject/NodeBuilder/ClassBuilder.php

This file was deleted.

15 changes: 0 additions & 15 deletions packages/PhpDocParser/ValueObject/NodeBuilder/MethodBuilder.php

This file was deleted.

15 changes: 0 additions & 15 deletions packages/PhpDocParser/ValueObject/NodeBuilder/NamespaceBuilder.php

This file was deleted.

15 changes: 0 additions & 15 deletions packages/PhpDocParser/ValueObject/NodeBuilder/ParamBuilder.php

This file was deleted.

15 changes: 0 additions & 15 deletions packages/PhpDocParser/ValueObject/NodeBuilder/PropertyBuilder.php

This file was deleted.

15 changes: 0 additions & 15 deletions packages/PhpDocParser/ValueObject/NodeBuilder/TraitUseBuilder.php

This file was deleted.

21 changes: 0 additions & 21 deletions packages/PhpDocParser/ValueObject/NodeBuilder/UseBuilder.php

This file was deleted.

5 changes: 0 additions & 5 deletions packages/Set/ValueObject/SetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,4 @@ final class SetList implements SetListInterface
* @var string
*/
public const EARLY_RETURN = __DIR__ . '/../../../config/set/early-return.php';

/**
* @var string
*/
public const RECTOR_CONFIG = __DIR__ . '/../../../config/set/rector-config.php';
}
7 changes: 0 additions & 7 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ parameters:
- '#Access to an undefined property PhpParser\\Node\\FunctionLike\|PhpParser\\Node\\Stmt\\If_\:\:\$stmts#'

- '#Cognitive complexity for "Rector\\CodeQuality\\Rector\\Isset_\\IssetOnPropertyObjectToPropertyExistsRector\:\:refactor\(\)" is \d+, keep it under 10#'
- '#Cognitive complexity for "Rector\\DogFood\\Rector\\Closure\\UpgradeRectorConfigRector\:\:refactor\(\)" is \d+, keep it under 10#'

- '#(.*?) class\-string, string given#'

Expand Down Expand Up @@ -724,12 +723,6 @@ parameters:
message: "#Class cognitive complexity is 69, keep it under 50#"
path: "packages/PhpDocParser/PhpDocParser/PhpDocNodeTraverser.php"

# update after https://github.com/nikic/PHP-Parser/pull/869 gets released
-
message: '#Method Rector\\PhpDocParser\\TypeAwareNodeFinder\:\:(.*?) should return (.*?) but returns (.*?)#'
paths:
- "packages/PhpDocParser/PhpDocParser/TypeAwareNodeFinder.php"
- "packages/PhpDocParser/TypeAwareNodeFinder.php"
-
message: '#Use explicit names over dynamic ones#'
path: "packages/PhpDocParser/NodeValue/NodeValueResolver/FuncCallValueResolver.php"
Expand Down

This file was deleted.

0 comments on commit 74f6b18

Please sign in to comment.