Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic call to static method configurationIsCached() / routesAreCached(). #483

Closed
jooola opened this issue Mar 3, 2020 · 9 comments
Closed
Labels
bug Something isn't working

Comments

@jooola
Copy link

jooola commented Mar 3, 2020

  • 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']);
            });
        });
    }
}
@jooola jooola changed the title Dynamic call to static method Illuminate\Foundation\Application::configurationIsCached() and routesAreCached(). Dynamic call to static method Application configurationIsCached() / routesAreCached(). Mar 3, 2020
@jooola jooola changed the title Dynamic call to static method Application configurationIsCached() / routesAreCached(). Dynamic call to static method configurationIsCached() / routesAreCached(). Mar 3, 2020
@canvural
Copy link
Collaborator

canvural commented Mar 3, 2020

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?

@canvural canvural added the bug Something isn't working label Mar 9, 2020
@canvural
Copy link
Collaborator

canvural commented Mar 9, 2020

#355 might be related also.

I'll try to investigate later this week.

@WoLfulus
Copy link

WoLfulus commented Mar 11, 2020

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.

@jooola
Copy link
Author

jooola commented Mar 11, 2020

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.

@jooola
Copy link
Author

jooola commented Mar 23, 2020

Just opened a ticket here laravel/framework#32079

@canvural
Copy link
Collaborator

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.

@WoLfulus
Copy link

WoLfulus commented Apr 3, 2020

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().
}

@nunomaduro
Copy link
Collaborator

I was not able to produce this issue with a fresh laravel installation + that code + Larastan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants