Bug Report
| Subject |
Details |
| Rector version |
e.g. v2.1.7 |
It changes [RequestContext::class, 'fromUri'] into RequestContext::fromUri(...), but unfortunately in this case it is invalid.
After the change I'm getting this error:
Symfony\Component\DependencyInjection\Loader\Configurator\ServiceConfigurator::factory(): Argument #1 ($factory) must be of type Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator|Symfony\Component\ExpressionLanguage\Expression|array|string, Closure given, called in […]/routing.php on line 17
Minimal PHP Code Causing Issue
<?php
declare(strict_types=1);
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\Routing\RequestContext;
/**
* routing.php
*/
return static function (ContainerConfigurator $container): void {
$container->services()
->set('router.request_context', RequestContext::class)
->factory([RequestContext::class, 'fromUri'])
->args([
'',
])
->alias(RequestContext::class, 'router.request_context');
};
Notice that factory method takes an array, but not \Closure nor callable: https://github.com/symfony/symfony/blob/v7.3.4/src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/FactoryTrait.php#L25
Actually they allow \Closure in the newest (not released yet) 7.4 version: https://github.com/symfony/symfony/blob/866757551299596f8dfb778394da5bc27b53df95/src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/FactoryTrait.php#L25
But for now, the Rector's change is invalid.
Expected Behaviour
Keep [RequestContext::class, 'fromUri'] in this particular case.
Bug Report
It changes
[RequestContext::class, 'fromUri']intoRequestContext::fromUri(...), but unfortunately in this case it is invalid.After the change I'm getting this error:
Minimal PHP Code Causing Issue
Notice that
factorymethod takes anarray, but not\Closurenorcallable: https://github.com/symfony/symfony/blob/v7.3.4/src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/FactoryTrait.php#L25Actually they allow
\Closurein the newest (not released yet) 7.4 version: https://github.com/symfony/symfony/blob/866757551299596f8dfb778394da5bc27b53df95/src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/FactoryTrait.php#L25But for now, the Rector's change is invalid.
Expected Behaviour
Keep
[RequestContext::class, 'fromUri']in this particular case.