Updated Rector to commit 5fc8c1a0539ba0f4ff29ed90f29633d4414e3ff6

5fc8c1a053 Replace ParametersAcceptorSelector::selectSingle() with ParametersAcceptorSelectorVariantsWrapper::select() when possible (#3361)
This commit is contained in:
Tomas Votruba 2023-02-08 10:25:24 +00:00
parent 73d7bba3b0
commit f0b34d4760
16 changed files with 233 additions and 38 deletions

View File

@ -8,7 +8,6 @@ use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\Native\NativeMethodReflection;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\Type;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
@ -57,15 +56,11 @@ final class MethodParameterTypeResolver
return [];
}
$parameterTypes = [];
if ($node instanceof ClassMethod) {
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants());
} else {
$scope = $node->getAttribute(AttributeKey::SCOPE);
if (!$scope instanceof Scope) {
return [];
}
$parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select($methodReflection, $node, $scope);
$scope = $node->getAttribute(AttributeKey::SCOPE);
if (!$scope instanceof Scope) {
return [];
}
$parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select($methodReflection, $node, $scope);
foreach ($parametersAcceptor->getParameters() as $parameterReflection) {
$parameterTypes[] = $parameterReflection->getType();
}

View File

@ -7,9 +7,9 @@ use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\FunctionVariant;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper;
/**
* @api
*/
@ -23,7 +23,7 @@ final class ClassMethodReturnTypeResolver
return new MixedType();
}
$extendedMethodReflection = $classReflection->getMethod($methodName, $scope);
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($extendedMethodReflection->getVariants());
$parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select($extendedMethodReflection, $classMethod, $scope);
if (!$parametersAcceptor instanceof FunctionVariant) {
return new MixedType();
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'a3bc2dcf8045157aafb20645b9e3cf49fa0542fb';
public const PACKAGE_VERSION = '5fc8c1a0539ba0f4ff29ed90f29633d4414e3ff6';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-02-08 09:14:25';
public const RELEASE_DATE = '2023-02-08 10:20:58';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit6a31b70255335038789a0563cb43e5af::getLoader();
return ComposerAutoloaderInite45af38a526e696c0d7cf01eefc78fd9::getLoader();

View File

@ -2579,6 +2579,7 @@ return array(
'Rector\\Symfony\\Rector\\Closure\\ContainerGetNameToTypeInTestsRector' => $vendorDir . '/rector/rector-symfony/src/Rector/Closure/ContainerGetNameToTypeInTestsRector.php',
'Rector\\Symfony\\Rector\\Closure\\ServiceSetStringNameToClassNameRector' => $vendorDir . '/rector/rector-symfony/src/Rector/Closure/ServiceSetStringNameToClassNameRector.php',
'Rector\\Symfony\\Rector\\Closure\\ServiceSettersToSettersAutodiscoveryRector' => $vendorDir . '/rector/rector-symfony/src/Rector/Closure/ServiceSettersToSettersAutodiscoveryRector.php',
'Rector\\Symfony\\Rector\\Closure\\ServiceTagsToDefaultsAutoconfigureRector' => $vendorDir . '/rector/rector-symfony/src/Rector/Closure/ServiceTagsToDefaultsAutoconfigureRector.php',
'Rector\\Symfony\\Rector\\Closure\\ServicesSetNameToSetTypeRector' => $vendorDir . '/rector/rector-symfony/src/Rector/Closure/ServicesSetNameToSetTypeRector.php',
'Rector\\Symfony\\Rector\\ConstFetch\\ConstraintUrlOptionRector' => $vendorDir . '/rector/rector-symfony/src/Rector/ConstFetch/ConstraintUrlOptionRector.php',
'Rector\\Symfony\\Rector\\FuncCall\\ReplaceServiceArgumentRector' => $vendorDir . '/rector/rector-symfony/src/Rector/FuncCall/ReplaceServiceArgumentRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit6a31b70255335038789a0563cb43e5af
class ComposerAutoloaderInite45af38a526e696c0d7cf01eefc78fd9
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit6a31b70255335038789a0563cb43e5af
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit6a31b70255335038789a0563cb43e5af', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInite45af38a526e696c0d7cf01eefc78fd9', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit6a31b70255335038789a0563cb43e5af', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInite45af38a526e696c0d7cf01eefc78fd9', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit6a31b70255335038789a0563cb43e5af::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInite45af38a526e696c0d7cf01eefc78fd9::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit6a31b70255335038789a0563cb43e5af::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInite45af38a526e696c0d7cf01eefc78fd9::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit6a31b70255335038789a0563cb43e5af
class ComposerStaticInite45af38a526e696c0d7cf01eefc78fd9
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2826,6 +2826,7 @@ class ComposerStaticInit6a31b70255335038789a0563cb43e5af
'Rector\\Symfony\\Rector\\Closure\\ContainerGetNameToTypeInTestsRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/Closure/ContainerGetNameToTypeInTestsRector.php',
'Rector\\Symfony\\Rector\\Closure\\ServiceSetStringNameToClassNameRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/Closure/ServiceSetStringNameToClassNameRector.php',
'Rector\\Symfony\\Rector\\Closure\\ServiceSettersToSettersAutodiscoveryRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/Closure/ServiceSettersToSettersAutodiscoveryRector.php',
'Rector\\Symfony\\Rector\\Closure\\ServiceTagsToDefaultsAutoconfigureRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/Closure/ServiceTagsToDefaultsAutoconfigureRector.php',
'Rector\\Symfony\\Rector\\Closure\\ServicesSetNameToSetTypeRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/Closure/ServicesSetNameToSetTypeRector.php',
'Rector\\Symfony\\Rector\\ConstFetch\\ConstraintUrlOptionRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/ConstFetch/ConstraintUrlOptionRector.php',
'Rector\\Symfony\\Rector\\FuncCall\\ReplaceServiceArgumentRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/FuncCall/ReplaceServiceArgumentRector.php',
@ -3097,9 +3098,9 @@ class ComposerStaticInit6a31b70255335038789a0563cb43e5af
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit6a31b70255335038789a0563cb43e5af::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6a31b70255335038789a0563cb43e5af::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit6a31b70255335038789a0563cb43e5af::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInite45af38a526e696c0d7cf01eefc78fd9::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInite45af38a526e696c0d7cf01eefc78fd9::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInite45af38a526e696c0d7cf01eefc78fd9::$classMap;
}, null, ClassLoader::class);
}

View File

@ -2062,12 +2062,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "89e994ffb68921d571bbf5b8e1d59280b7f30a50"
"reference": "d30ef6be6c074f080cc96db866a243ab327e04f3"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/89e994ffb68921d571bbf5b8e1d59280b7f30a50",
"reference": "89e994ffb68921d571bbf5b8e1d59280b7f30a50",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/d30ef6be6c074f080cc96db866a243ab327e04f3",
"reference": "d30ef6be6c074f080cc96db866a243ab327e04f3",
"shasum": ""
},
"require": {
@ -2082,7 +2082,6 @@
"phpstan\/phpstan-webmozart-assert": "^1.2",
"phpunit\/phpunit": "^10.0",
"rector\/phpstan-rules": "^0.6",
"rector\/rector-debugging": "dev-main",
"rector\/rector-generator": "^0.6",
"rector\/rector-src": "dev-main",
"symfony\/routing": "^6.1",
@ -2090,7 +2089,6 @@
"symfony\/security-http": "^6.1",
"symplify\/easy-ci": "^11.1",
"symplify\/easy-coding-standard": "^11.2",
"symplify\/monorepo-builder": "^11.2",
"symplify\/phpstan-extensions": "^11.1",
"symplify\/phpstan-rules": "^11.2",
"symplify\/rule-doc-generator": "^11.2",
@ -2099,7 +2097,7 @@
"tomasvotruba\/type-coverage": "^0.0.9",
"tomasvotruba\/unused-public": "^0.0.34"
},
"time": "2023-02-07T01:40:50+00:00",
"time": "2023-02-08T09:57:13+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main ea9cf46'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 46346e2'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main ee461b1'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 89e994f'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main ea9cf46'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 46346e2'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main ee461b1'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main d30ef6b'));
private function __construct()
{
}

View File

@ -15,7 +15,6 @@
"phpstan\/phpstan-webmozart-assert": "^1.2",
"phpunit\/phpunit": "^10.0",
"rector\/phpstan-rules": "^0.6",
"rector\/rector-debugging": "dev-main",
"rector\/rector-generator": "^0.6",
"rector\/rector-src": "dev-main",
"symfony\/routing": "^6.1",
@ -23,7 +22,6 @@
"symfony\/security-http": "^6.1",
"symplify\/easy-ci": "^11.1",
"symplify\/easy-coding-standard": "^11.2",
"symplify\/monorepo-builder": "^11.2",
"symplify\/phpstan-extensions": "^11.1",
"symplify\/phpstan-rules": "^11.2",
"symplify\/rule-doc-generator": "^11.2",

View File

@ -1,4 +1,4 @@
# 76 Rules Overview
# 77 Rules Overview
## ActionSuffixRemoverRector
@ -1484,7 +1484,7 @@ Change `$service->set()` string names to class-type-based names, to allow `$cont
## ServiceSettersToSettersAutodiscoveryRector
Change `$services->set(...,` ...) to `$services->load(...,` ...) where meaning ful
Change `$services->set(...,` ...) to `$services->load(...,` ...) where meaningful
- class: [`Rector\Symfony\Rector\Closure\ServiceSettersToSettersAutodiscoveryRector`](../src/Rector/Closure/ServiceSettersToSettersAutodiscoveryRector.php)
@ -1507,6 +1507,29 @@ Change `$services->set(...,` ...) to `$services->load(...,` ...) where meaning f
<br>
## ServiceTagsToDefaultsAutoconfigureRector
Change `$services->set(...,` ...)->tag(...) to `$services->defaults()->autodiscovery()` where meaningful
- class: [`Rector\Symfony\Rector\Closure\ServiceTagsToDefaultsAutoconfigureRector`](../src/Rector/Closure/ServiceTagsToDefaultsAutoconfigureRector.php)
```diff
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use App\Command\SomeCommand;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
+ $services->defaults()
+ ->autoconfigure();
- $services->set(SomeCommand::class)
- ->tag('console.command');
+ $services->set(SomeCommand::class);
};
```
<br>
## ServicesSetNameToSetTypeRector
Change `$services->set("name_type",` SomeType::class) to bare type, useful since Symfony 3.4

View File

@ -13,7 +13,6 @@ use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->importNames();
$rectorConfig->paths([__DIR__ . '/src', __DIR__ . '/tests']);
$rectorConfig->parallel();
$rectorConfig->skip([
'*/Fixture/*',
'*/Source/*',

View File

@ -3,9 +3,14 @@
declare (strict_types=1);
namespace Rector\Symfony\NodeAnalyzer;
use PhpParser\Node;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\NodeTraverser;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
final class SymfonyPhpClosureDetector
{
/**
@ -13,9 +18,21 @@ final class SymfonyPhpClosureDetector
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
public function __construct(NodeNameResolver $nodeNameResolver)
/**
* @readonly
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
*/
private $betterNodeFinder;
/**
* @readonly
* @var \Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser
*/
private $simpleCallableNodeTraverser;
public function __construct(NodeNameResolver $nodeNameResolver, BetterNodeFinder $betterNodeFinder, SimpleCallableNodeTraverser $simpleCallableNodeTraverser)
{
$this->nodeNameResolver = $nodeNameResolver;
$this->betterNodeFinder = $betterNodeFinder;
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
}
public function detect(Closure $closure) : bool
{
@ -28,4 +45,28 @@ final class SymfonyPhpClosureDetector
}
return $this->nodeNameResolver->isName($firstParam->type, 'Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\ContainerConfigurator');
}
public function hasDefaultsAutoconfigure(Closure $closure) : bool
{
$hasDefaultsAutoconfigure = \false;
// has defaults autoconfigure?
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($closure, function (Node $node) use(&$hasDefaultsAutoconfigure) {
if (!$node instanceof MethodCall) {
return null;
}
if (!$this->nodeNameResolver->isName($node->name, 'autoconfigure')) {
return null;
}
/** @var MethodCall[] $methodCalls */
$methodCalls = $this->betterNodeFinder->findInstanceOf($node, MethodCall::class);
foreach ($methodCalls as $methodCall) {
if (!$this->nodeNameResolver->isName($methodCall->name, 'defaults')) {
continue;
}
$hasDefaultsAutoconfigure = \true;
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
}
return null;
});
return $hasDefaultsAutoconfigure;
}
}

View File

@ -58,7 +58,7 @@ final class ServiceSettersToSettersAutodiscoveryRector extends AbstractRector
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change $services->set(..., ...) to $services->load(..., ...) where meaning ful', [new CodeSample(<<<'CODE_SAMPLE'
return new RuleDefinition('Change $services->set(..., ...) to $services->load(..., ...) where meaningful', [new CodeSample(<<<'CODE_SAMPLE'
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use App\Services\FistService;

View File

@ -0,0 +1,139 @@
<?php
declare (strict_types=1);
namespace Rector\Symfony\Rector\Closure;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Expression;
use Rector\Core\Rector\AbstractRector;
use Rector\Symfony\NodeAnalyzer\SymfonyPhpClosureDetector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Symfony\Tests\Rector\Closure\ServiceTagsToDefaultsAutoconfigureRector\ServiceTagsToDefaultsAutoconfigureRectorTest
*/
final class ServiceTagsToDefaultsAutoconfigureRector extends AbstractRector
{
/**
* @var string[]
*/
private const AUTOCONFIGUREABLE_TAGS = [
// @todo fill
'twig.extension',
'console.command',
'kernel.event_subscriber',
'monolog.logger',
'security.voter',
];
/**
* @readonly
* @var \Rector\Symfony\NodeAnalyzer\SymfonyPhpClosureDetector
*/
private $symfonyPhpClosureDetector;
public function __construct(SymfonyPhpClosureDetector $symfonyPhpClosureDetector)
{
$this->symfonyPhpClosureDetector = $symfonyPhpClosureDetector;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change $services->set(..., ...)->tag(...) to $services->defaults()->autodiscovery() where meaningful', [new CodeSample(<<<'CODE_SAMPLE'
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use App\Command\SomeCommand;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(SomeCommand::class)
->tag('console.command');
};
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use App\Command\SomeCommand;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->defaults()
->autoconfigure();
$services->set(SomeCommand::class);
};
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Closure::class];
}
/**
* @param Closure $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->symfonyPhpClosureDetector->detect($node)) {
return null;
}
$hasDefaultsAutoconfigure = $this->symfonyPhpClosureDetector->hasDefaultsAutoconfigure($node);
$hasChanged = \false;
$this->traverseNodesWithCallable($node->stmts, function (Node $node) use(&$hasChanged) : ?Expr {
if (!$node instanceof MethodCall) {
return null;
}
if (!$this->isName($node->name, 'tag')) {
return null;
}
// is autoconfigureable tag?
$firstArg = $node->getArgs()[0];
$tagValue = $this->valueResolver->getValue($firstArg->value);
if (!\in_array($tagValue, self::AUTOCONFIGUREABLE_TAGS, \true)) {
return null;
}
// remove tag() method by returning nested method call
$hasChanged = \true;
return $node->var;
});
if ($hasChanged === \false) {
return null;
}
if ($hasDefaultsAutoconfigure === \false) {
$this->addDefaultAutoconfigure($node);
}
return $node;
}
private function createDefaultsAutoconfigureExpression() : Expression
{
$defaultsMethodCall = new MethodCall(new Variable('services'), 'defaults');
$autoconfigureMethodCall = new MethodCall($defaultsMethodCall, 'autoconfigure');
return new Expression($autoconfigureMethodCall);
}
private function addDefaultAutoconfigure(Closure $closure) : void
{
foreach ($closure->stmts as $key => $nodeStmt) {
if (!$nodeStmt instanceof Expression) {
continue;
}
if (!$nodeStmt->expr instanceof Assign) {
continue;
}
$assign = $nodeStmt->expr;
if (!$assign->var instanceof Variable) {
continue;
}
if (!$this->isName($assign->var, 'services')) {
continue;
}
// add defaults here, right after assign :)
$autoconfigureExpression = $this->createDefaultsAutoconfigureExpression();
\array_splice($closure->stmts, $key + 1, 0, [$autoconfigureExpression]);
break;
}
}
}