Skip to content

Commit

Permalink
[DX] Move configure to direct call in RectorConfig (#2367)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed May 27, 2022
1 parent 213b14d commit 7adde58
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
12 changes: 11 additions & 1 deletion packages/Config/RectorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\Config;

use Rector\Core\Configuration\Option;
use Rector\Core\Configuration\ValueObjectInliner;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Core\ValueObject\PhpVersion;
Expand Down Expand Up @@ -114,8 +115,17 @@ public function ruleWithConfiguration(string $rectorClass, array $configuration)

$services = $this->services();

// decorate with value object inliner so Symfony understands, see https://getrector.org/blog/2020/09/07/how-to-inline-value-object-in-symfony-php-config
array_walk_recursive($configuration, function (&$value) {
if (is_object($value)) {
$value = ValueObjectInliner::inline($value);
}

return $value;
});

$services->set($rectorClass)
->configure($configuration);
->call('configure', [$configuration]);
}

/**
Expand Down
31 changes: 6 additions & 25 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,6 @@ parameters:
message: '#Call to static method Webmozart\\Assert\\Assert\:\:allString\(\) with array<string> will always evaluate to true#'
path: packages/Config/RectorConfig.php

# foreaching all stmts

- '#Method "processStmt\(\)" returns bool type, so the name should start with is/has/was#'
- '#Method "refactorReturnAndAssign\(\)" returns bool type, so the name should start with is/has/was#'

Expand Down Expand Up @@ -616,38 +614,16 @@ parameters:
path: rules/Renaming/NodeManipulator/ClassRenamer.php
message: '#Use separate function calls with readable variable names#'



# false positive by php-parser, the args can be null


# known type




# doc validation
-
message: '#Call to function array_key_exists\(\) with (.*?) and array(.*?) will always evaluate to true#'
path: packages/FileFormatter/ValueObject/Indent.php





# hash key
-
path: rules/Renaming/NodeManipulator/ClassRenamer.php
message: '#Use separate function calls with readable variable names#'



# false positive by php-parser, the args can be null


# known type


- '#Cognitive complexity for "Rector\\NodeTypeResolver\\PHPStan\\Scope\\PHPStanNodeScopeResolver\:\:processNodes\(\)" is \d+, keep it under 10#'

# depends on falsy docs
Expand All @@ -659,7 +635,6 @@ parameters:
path: packages/FileFormatter/ValueObject/Indent.php



# autoload check in bin file
-
message: '#Function "class_exists\(\)" cannot be used/left in the code\: use ReflectionProvider\->has\*\(\) instead#'
Expand Down Expand Up @@ -711,3 +686,9 @@ parameters:
-
message: '#Class cognitive complexity is 55, keep it under 50#'
path: src/PhpParser/Printer/BetterStandardPrinter.php #41

# trust in 3rd party api
- '#Parameter \#1 \$indentStyle of method Rector\\FileFormatter\\ValueObjectFactory\\EditorConfigConfigurationBuilder\:\:withIndentStyle\(\) expects (.*?) string given#'

# list() function accepts null arguments
- '#Parameter \#2 \$args of class PhpParser\\Node\\Expr\\FuncCall constructor expects array<PhpParser\\Node\\Arg\|PhpParser\\Node\\VariadicPlaceholder>, array<int, PhpParser\\Node\\Arg\|null> given#'

0 comments on commit 7adde58

Please sign in to comment.