Larastan: `$app->environment` with parameter

Created on 24 Jul 2018  路  6Comments  路  Source: nunomaduro/larastan

Illuminate\Contracts\Foundation\Application defines the environment function as follows

/**
 * Get or check the current application environment.
 *
 * @return string
 */
public function environment();

The concrete Application implementation in Illuminate\Foundation\Application implements it like so:

/**
 * Get or check the current application environment.
 *
 * @return string|bool
 */
public function environment()
{
    if (func_num_args() > 0) {
        $patterns = is_array(func_get_arg(0)) ? func_get_arg(0) : func_get_args();

        return Str::is($patterns, $this['env']);
    }

    return $this['env'];
}

Meaning you're able to pass arguments to the function, though it's never documented 馃檮

Not sure whether a docblock or optional paramter must be added in the core, or if you want to fix it in this package. Anyways, when doing this:

$this->app->environment('local')

There's this error:

Method Illuminate\Contracts\Foundation\Application::environment() invoked with 1 parameter, 0 required.
false positive

All 6 comments

@brendt Submit a Laravel PR!

A PR addressing this issue has already been rejected: https://github.com/laravel/framework/pull/23533

@nunomaduro Could it be that it'll be the next one in ignoreErrors:?

@szepeviktor @brendt I will write an extension for this.

Any news? I commented on #184 but now i see there is also this issue.

This is resolved as of Laravel 5.8, see https://github.com/laravel/framework/commit/f0b7f49a7f6d15591859e7ecb06c090b02c68df6#diff-7b18a52eceff5eb716c1de268e98d55d

Was this page helpful?
0 / 5 - 0 ratings