diff --git a/config/level/laravel/laravel57.yaml b/config/level/laravel/laravel57.yaml index 28f2b7d9df2..60cf2fba231 100644 --- a/config/level/laravel/laravel57.yaml +++ b/config/level/laravel/laravel57.yaml @@ -5,3 +5,16 @@ services: addRoute: 'public' Illuminate\Contracts\Auth\Access\Gate: raw: 'public' + + Rector\Rector\Argument\ArgumentAdderRector: + Illuminate\Auth\Middleware\Authenticate: + authenticate: + name: 'request' + Illuminate\Foundation\Auth\ResetsPasswords: + sendResetResponse: + name: 'request' + type: 'Illuminate\Http\Illuminate\Http' + Illuminate\Foundation\Auth\SendsPasswordResetEmails: + sendResetLinkResponse: + name: 'request' + type: 'Illuminate\Http\Illuminate\Http' diff --git a/config/level/sylius/sylius10.yaml b/config/level/sylius/sylius10.yaml index 7247f96ea4a..0f2db0ec32f 100644 --- a/config/level/sylius/sylius10.yaml +++ b/config/level/sylius/sylius10.yaml @@ -26,11 +26,13 @@ services: Sylius\Component\Mailer\Sender\SenderInterface: send: 0: - code: '[]' + name: 'code' + default_value: '[]' Sylius\Component\Core\Repository\ProductRepositoryInterface: findOneBySlug: 2: - __unknown__: false + name: '__unknown__' + default_value: false Rector\Rector\ClassMethod\AddReturnTypeDeclarationRector: Sylius\Component\Order\Model\OrderInterface: diff --git a/config/level/symfony/symfony32.yaml b/config/level/symfony/symfony32.yaml index 21bca905ad0..e579dbc3dfc 100644 --- a/config/level/symfony/symfony32.yaml +++ b/config/level/symfony/symfony32.yaml @@ -4,4 +4,5 @@ services: Symfony\Component\DependencyInjection\ContainerBuilder: addCompilerPass: 2: - priority: 0 + name: 'priority' + default_value: 0 diff --git a/config/level/symfony/symfony33.yaml b/config/level/symfony/symfony33.yaml index ab9f1927e67..027f8bc0047 100644 --- a/config/level/symfony/symfony33.yaml +++ b/config/level/symfony/symfony33.yaml @@ -5,14 +5,17 @@ services: Symfony\Component\DependencyInjection\ContainerBuilder: compile: 2: - __unknown__: 0 + name: '__unknown__' + default_value: 0 addCompilerPass: 2: - priority: 0 + name: 'priority' + default_value: 0 Symfony\Component\DependencyInjection\Compiler\ServiceReferenceGraph: connect: 6: - weak: false + name: 'weak' + default_value: false Rector\Symfony\Rector\Console\ConsoleExceptionToErrorEventConstantRector: ~ diff --git a/config/level/symfony/symfony42.yaml b/config/level/symfony/symfony42.yaml index 2bcdce2ad94..f39aacc0314 100644 --- a/config/level/symfony/symfony42.yaml +++ b/config/level/symfony/symfony42.yaml @@ -20,7 +20,7 @@ services: Symfony\Component\BrowserKit\Client: submit: 2: - # $serverParameters + name: 'serverParameters' default_value: [] # https://github.com/symfony/symfony/commit/f634afdb6f573e4af8d89aaa605e0c7d4058676d diff --git a/src/Rector/Argument/ArgumentAdderRector.php b/src/Rector/Argument/ArgumentAdderRector.php index dd8bffca869..1c08f9bd71a 100644 --- a/src/Rector/Argument/ArgumentAdderRector.php +++ b/src/Rector/Argument/ArgumentAdderRector.php @@ -8,6 +8,8 @@ use PhpParser\Node\Arg; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Variable; +use PhpParser\Node\Identifier; +use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; use Rector\Rector\AbstractRector; @@ -35,7 +37,9 @@ final class ArgumentAdderRector extends AbstractRector 'SomeExampleClass' => [ 'someMethod' => [ 0 => [ + 'name' => 'someArgument', 'default_value' => 'true', + 'type' => 'SomeType', ], ], ], @@ -118,20 +122,35 @@ CODE_SAMPLE */ private function processPositionWithDefaultValues(Node $node, array $positionWithDefaultValues): void { - foreach ($positionWithDefaultValues as $position => $nameToValue) { - reset($nameToValue); - $name = key($nameToValue); - if ($name === null || is_int($name)) { - continue; - } - - $value = $nameToValue[$name]; + foreach ($positionWithDefaultValues as $position => $parameterConfiguration) { + $name = $parameterConfiguration['name']; + $defaultValue = $parameterConfiguration['default_value'] ?? null; + $type = $parameterConfiguration['type'] ?? null; if ($node instanceof ClassMethod) { - $node->params[$position] = new Param(new Variable($name), BuilderHelpers::normalizeValue($value)); + $this->addClassMethodParam($node, $name, $defaultValue, $type, $position); } else { - $node->args[$position] = new Arg(BuilderHelpers::normalizeValue($value)); + $arg = new Arg(BuilderHelpers::normalizeValue($defaultValue)); + $node->args[$position] = $arg; } } } + + /** + * @param mixed $defaultValue + */ + private function addClassMethodParam( + ClassMethod $classMethod, + string $name, + $defaultValue, + ?string $type, + int $position + ): void { + $param = new Param(new Variable($name), BuilderHelpers::normalizeValue($defaultValue)); + if ($type) { + $param->type = ctype_upper($type[0]) ? new FullyQualified($type) : new Identifier($type); + } + + $classMethod->params[$position] = $param; + } } diff --git a/tests/Rector/Argument/ArgumentAdderRector/ArgumentAdderRectorTest.php b/tests/Rector/Argument/ArgumentAdderRector/ArgumentAdderRectorTest.php index ccc291430a8..436ab333da0 100644 --- a/tests/Rector/Argument/ArgumentAdderRector/ArgumentAdderRectorTest.php +++ b/tests/Rector/Argument/ArgumentAdderRector/ArgumentAdderRectorTest.php @@ -24,9 +24,22 @@ final class ArgumentAdderRectorTest extends AbstractRectorTestCase */ protected function getRectorConfiguration(): array { - return [ContainerBuilder::class => [ - 'compile' => [['isCompiled' => false]], - 'addCompilerPass' => [2 => ['priority' => 0]], - ]]; + return [ + ContainerBuilder::class => [ + 'compile' => [ + [ + 'name' => 'isCompiled', + 'default_value' => false, + ], + ], + 'addCompilerPass' => [ + 2 => [ + 'name' => 'priority', + 'default_value' => 0, + 'type' => 'SomeType', + ], + ], + ], + ]; } } diff --git a/tests/Rector/Argument/ArgumentAdderRector/Fixture/fixture3.php.inc b/tests/Rector/Argument/ArgumentAdderRector/Fixture/fixture3.php.inc index 2c498f55d05..2da5b6cb2af 100644 --- a/tests/Rector/Argument/ArgumentAdderRector/Fixture/fixture3.php.inc +++ b/tests/Rector/Argument/ArgumentAdderRector/Fixture/fixture3.php.inc @@ -21,7 +21,7 @@ use Rector\Tests\Rector\Argument\ArgumentAdderRector\Source\ContainerBuilder; class CustomContainerBuilder extends ContainerBuilder { - public function addCompilerPass($pass, $type, $priority = 0) + public function addCompilerPass($pass, $type, \SomeType $priority = 0) { } }