--level used: 8We just upgraded to laravel v7, and these 2 warnings pops out.
You can see the PR here https://github.com/directus/api-next/pull/148
------ -------------------------------------------------------------
Line src/Laravel/Providers/DirectusProvider.php
------ -------------------------------------------------------------
52 Dynamic call to static method
Illuminate\Foundation\Application::configurationIsCached().
95 Dynamic call to static method
Illuminate\Foundation\Application::routesAreCached().
------ -------------------------------------------------------------
I read the code and both methods are not static.
I might be missing something huge. Not sure.
See more at https://github.com/directus/api-next/blob/master/src/Laravel/Providers/DirectusProvider.php
class DirectusProvider extends ServiceProvider
{
/**
* Merges configuration.
*/
private function registerConfigs(): void
{
/** @var bool */
$debug = config('app.debug', false);
// Do not load configs if it's cached.
if ($this->app->configurationIsCached() && !$debug) {
return;
}
$this->mergeConfigFrom(
__DIR__.'/../Config/directus.php',
'directus'
);
}
/**
* Service boot.
*/
private function bootRoutes(): void
{
/** @var bool */
$debug = config('app.debug', false);
// Do not create routes if it's cached.
if ($this->app->routesAreCached() && !$debug) {
return;
}
$options = config('directus.routes.options', [
'prefix' => '/',
]);
// Directus base
Route::group($options, function (): void {
// Server
// https://docs.directus.io/api/server.html#server
Route::group([
'prefix' => 'server',
], function (): void {
Route::get('info', [ServerController::class, 'info']);
Route::get('ping', [ServerController::class, 'ping']);
});
// Items
Route::group([
'prefix' => 'items',
'middleware' => [
CollectionMiddleware::class,
],
], function (): void {
// Collection
Route::get('{collection}', [CollectionController::class, 'index']);
Route::get('{collection}/{id}', [CollectionController::class, 'show']);
});
});
}
}
Hi,
Thanks for reporting this.
Do you have any other PHPStan extension installed? Like strict rules.
Do you any annotation for the Application class anywhere that is also read by PHPStan?
Yes, we have strict rules enabled.
We don't have any annotations.
This is the class that trigger the warning https://laravel.com/api/7.x/Illuminate/Foundation/Application.html
Here are the functions in the framework repository.
https://github.com/laravel/framework/blob/7.x/src/Illuminate/Foundation/Application.php#L945
https://github.com/laravel/framework/blob/7.x/src/Illuminate/Foundation/Application.php#L965
I'll try to investigate later this week.
Just to confirm... is this related to v7? I don't remember getting those in v6
I don't really know how those checks are made, but maybe it's the class definition conflicting with the Facade definition?
In Facade it's declared as static, and interface/class it's a class method.
We just upgraded to laravel v7, and these 2 warnings pops out.
Yes, this warnings popped when I upgraded to laravel v7, see the issue description.
Just opened a ticket here https://github.com/laravel/framework/issues/32079
This is not a bug in Laravel itself. It is about Larastan. And when strict rules used together with Larastan it causes this issue.
I still didn't quite figure it out yet, but I'll spend more time on it.
This is also happening for validate in Request $request too. Maybe it's all the Macroable ones? The Request class seems to be annotated with @method though.
public function action(Request $request) {
$request->validate([ ... ]); // Dynamic call to static method Illuminate\Http\Request::validate().
}