Problem
RequestStaticValidateToInjectRector appears to be too broad.
It currently rewrites a static call on Illuminate\Foundation\Http\FormRequest into an instance call on an injected Illuminate\Http\Request, even though failOnUnknownFields() is a static API on FormRequest and does not exist on the base Request class.
This produces invalid code.
Minimal reproduction
Rector config
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use RectorLaravel\Rector\StaticCall\RequestStaticValidateToInjectRector;
return RectorConfig::configure()
->withPaths([__DIR__ . '/app'])
->withRules([
RequestStaticValidateToInjectRector::class,
]);
Input
<?php
declare(strict_types=1);
namespace App\Providers;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\ServiceProvider;
final class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
FormRequest::failOnUnknownFields();
}
}
Actual output
<?php
declare(strict_types=1);
namespace App\Providers;
use Illuminate\Http\Request;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\ServiceProvider;
final class AppServiceProvider extends ServiceProvider
{
public function boot(Request $request): void
{
$request->failOnUnknownFields();
}
}
Expected output
No change.
FormRequest::failOnUnknownFields() is a valid static call and should remain untouched.
Why this is a bug
failOnUnknownFields() exists on Illuminate\Foundation\Http\FormRequest, not on Illuminate\Http\Request.
So the transformation changes:
- a valid static class-level configuration call
- into an instance method call on the wrong type
which makes the result invalid.
Notes
The rule name and docs suggest it is intended for Request::validate() style rewrites, but the current implementation seems to rewrite arbitrary static calls on Request-like types.
Environment
rector/rector: 2.4.1
driftingly/rector-laravel: 2.3.0
laravel/framework: 13.4.0
Problem
RequestStaticValidateToInjectRectorappears to be too broad.It currently rewrites a static call on
Illuminate\Foundation\Http\FormRequestinto an instance call on an injectedIlluminate\Http\Request, even thoughfailOnUnknownFields()is a static API onFormRequestand does not exist on the baseRequestclass.This produces invalid code.
Minimal reproduction
Rector config
Input
Actual output
Expected output
No change.
FormRequest::failOnUnknownFields()is a valid static call and should remain untouched.Why this is a bug
failOnUnknownFields()exists onIlluminate\Foundation\Http\FormRequest, not onIlluminate\Http\Request.So the transformation changes:
which makes the result invalid.
Notes
The rule name and docs suggest it is intended for
Request::validate()style rewrites, but the current implementation seems to rewrite arbitrary static calls on Request-like types.Environment
rector/rector:2.4.1driftingly/rector-laravel:2.3.0laravel/framework:13.4.0