driftingly/rector-laravel

RouteActionCallableRector (Cannot autowire service)

Closed this issue · 7 comments

<?php

use Rector\Config\RectorConfig;
use RectorLaravel\Rector\StaticCall\RouteActionCallableRector;

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->paths([
        __DIR__ . '/routes',
    ]);

    $rectorConfig->ruleWithConfiguration(RouteActionCallableRector::class, [
        RouteActionCallableRector::NAMESPACE => 'App\Http\Controllers',
    ]);
};
 [ERROR] Cannot autowire service "RectorLaravel\Rector\StaticCall\RouteActionCallableRector": argument                  
         "$routerRegisterNodeAnalyzer" of method "__construct()" references class                                       
         "RectorLaravel\NodeFactory\RouterRegisterNodeAnalyzer" but no such service exists.  

Tested with both PHP 8.1.17,8.2.4

rector/rector: 0.15.24
driftingly/rector-laravel: 0.17.0

Any idea what i am doing wrong?

Encountered same issue

Added in the configuration:

$services = $rectorConfig->services();
    $services->defaults()->public()->autowire()->autoconfigure();
    $services->load('RectorLaravel\\', './vendor/driftingly/rector-laravel/src')
        ->exclude(['./vendor/driftingly/rector-laravel/src/{Rector,ValueObject}']);

Helps to run it, not sure that the command works for my routes, maybe my configurations are not correct.

@egorbwork Thanks for the suggestion. Seems to avoid the error, although it seems to do nothing...

@egorbwork Thanks for the suggestion. It seems to avoid the error, although it seems to do nothing...

Yes, I have rewritten for my need this rule, to cover more cases. I will open a pr in this repository later in 24 hours. You could check if my adjustments covered your needs too.

@fridzema tried to improve the routing process in this pr:
#101

@fridzema please try the latest version.

@egorbwork Thanks, works perfect now!