Completed
Push — master ( 0bdd85...3b978d )
by Frédéric
06:24
created

LocaleRouteServiceProvider::aliasMiddleware()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace CaribouFute\LocaleRoute;
4
5
use CaribouFute\LocaleRoute\Middleware\SetSessionLocale;
6
use CaribouFute\LocaleRoute\Prefix\Route as PrefixRoute;
7
use CaribouFute\LocaleRoute\Routing\LocaleRouter;
8
use Illuminate\Routing\Router;
9
use Illuminate\Support\ServiceProvider;
10
11
class LocaleRouteServiceProvider extends ServiceProvider
12
{
13
    protected $defer = false;
14
15
    public function boot(Router $router)
16
    {
17
        $this->publishes([__DIR__ . '/config/localeroute.php' => config_path('localeroute.php')]);
18
        $this->mergeConfigFrom(__DIR__ . '/config/localeroute.php', 'localeroute');
19
20
        $this->aliasMiddleware($router);
21
    }
22
23
    /**
24
     *  Adds locale.session middleware alias to both Laravel 5.4 (aliasMiddleware) and Laravel <5.4 (middleware)
25
     *  @param Router $router: the app router
0 ignored issues
show
Documentation introduced by
There is no parameter named $router:. Did you maybe mean $router?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
26
     *  @return void
27
     */
28
    protected function aliasMiddleware(Router $router)
29
    {
30
        if (method_exists($router, 'aliasMiddleware')) {
31
            $router->aliasMiddleware('locale.session', SetSessionLocale::class);
32
        } else {
33
            $router->middleware('locale.session', SetSessionLocale::class);
0 ignored issues
show
Bug introduced by
The method middleware() does not exist on Illuminate\Routing\Router. Did you maybe mean aliasMiddleware()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
34
        }
35
    }
36
37
    public function register()
38
    {
39
        $this->app->bind('locale-route', LocaleRouter::class);
40
        $this->app->bind('locale-route-url', PrefixRoute::class);
41
42
        config('config/localeroute.php');
43
    }
44
}
45