8000 add configure() method on ServiceConfiguator prototype · rectorphp/rector-src@bca22b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit bca22b1

Browse files
committed
add configure() method on ServiceConfiguator prototype
1 parent 0853c28 commit bca22b1

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"symplify/skipper": "^10.0",
5050
"symplify/smart-file-system": "^10.0",
5151
"symplify/symfony-php-config": "^10.0",
52+
"symplify/vendor-patches": "^10.0",
5253
"tracy/tracy": "^2.8",
5354
"webmozart/assert": "^1.10"
5455
},
@@ -70,7 +71,6 @@
7071
"symplify/phpstan-extensions": "^10.0",
7172
"symplify/phpstan-rules": "^10.0",
7273
"symplify/rule-doc-generator": "^10.0",
73-
"symplify/vendor-patches": "^10.0",
7474
"timeweb/phpstan-enum": "dev-22-upgrade-phpstan-to-1.0"
7575
},
7676
"replace": {

phpstan.neon

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,3 +514,11 @@ parameters:
514514
paths:
515515
- packages/StaticTypeMapper/PhpDocParser/IntersectionTypeMapper.php
516516
- packages/StaticTypeMapper/PhpParser/IntersectionTypeNodeMapper.php
517+
518+
-
519+
message: '#Use separate function calls with readable variable names#'
520+
path: src/DependencyInjection/Loader/Configurator/RectorServiceConfigurator.php
521+
522+
-
523+
message: '#\$service\-\>call\("configure", \[\[ \.\.\. \]\]\) must be followed by exact array#'
524+
path: src/DependencyInjection/Loader/Configurator/RectorServiceConfigurator.php

rector.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Rector\Set\ValueObject\LevelSetList;
1616
use Rector\Set\ValueObject\SetList;
1717
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
18-
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
1918

2019
return static function (ContainerConfigurator $containerConfigurator): void {
2120
// include the latest PHP version + all bellow in one config!
@@ -38,18 +37,18 @@
3837

3938
// phpunit
4039
$services->set(PreferThisOrSelfMethodCallRector::class)
41-
->call('configure', [[
40+
->configure([
4241
PreferThisOrSelfMethodCallRector::TYPE_TO_PREFERENCE => [
43-
TestCase::class => ValueObjectInliner::inline(PreferenceSelfThis::PREFER_THIS()),
42+
TestCase::class => PreferenceSelfThis::PREFER_THIS(),
4443
],
45-
]]);
44+
]);
4645

4746
$services->set(ReturnArrayClassMethodToYieldRector::class)
48-
->call('configure', [[
49-
ReturnArrayClassMethodToYieldRector::METHODS_TO_YIELDS => ValueObjectInliner::inline([
47+
->configure([
48+
ReturnArrayClassMethodToYieldRector::METHODS_TO_YIELDS => [
5049
new ReturnArrayClassMethodToYield('PHPUnit\Framework\TestCase', '*provide*'),
51-
]),
52-
]]);
50+
],
51+
]);
5352

5453
$parameters = $containerConfigurator->parameters();
5554

src/DependencyInjection/Loader/Configurator/RectorServiceConfigurator.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,28 @@
55
namespace Rector\Core\DependencyInjection\Loader\Configurator;
66

77
use Symfony\Component\DependencyInjection\Loader\Configurator\ServiceConfigurator;
8+
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
89

910
/**
11+
* @api
1012
* Same as Symfony service configurator, with extra "configure()" method for easier DX
1113
*/
1214
final class RectorServiceConfigurator extends ServiceConfigurator
1315
{
16+
/**
17+
* @param array<string, mixed> $configuration
18+
*/
19+
public function configure(array $configuration): void
20+
{
21+
// 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
22+
array_walk_recursive($configuration, function (&$value) {
23+
if (is_object($value)) {
24+
$value = ValueObjectInliner::inline($value);
25+
}
1426

27+
return $value;
28+
});
29+
30+
$this->call('configure', [$configuration]);
31+
}
1532
}

0 commit comments

Comments
 (0)
0