Larastan: Dynamic call to static method configurationIsCached() / routesAreCached().

Created on 3 Mar 2020  路  8Comments  路  Source: nunomaduro/larastan

  • Larastan Version: 0.5.2
  • --level used: 8

Description

We 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.

Laravel code where the issue was found

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']);
            });
        });
    }
}
bug

All 8 comments

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?

355 might be related also.

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.

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().
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

bogdankharchenko picture bogdankharchenko  路  4Comments

szepeviktor picture szepeviktor  路  4Comments

jdrieghe picture jdrieghe  路  4Comments

fico7489 picture fico7489  路  3Comments

tranba picture tranba  路  4Comments