Test Failed
Push — feature-laravel-5.4 ( 2b4b90...5bfdc4 )
by Kirill
03:52
created

NavigationServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of laravel.su package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types = 1);
9
10
namespace App\Providers;
11
12
use App\Services\NavMatcher;
13
use Illuminate\Container\Container;
14
use Illuminate\Routing\Route;
15
use Illuminate\Routing\Router;
16
use Illuminate\Support\ServiceProvider;
17
18
/**
19
 * Class NavigationServiceProvider.
20
 */
21
class NavigationServiceProvider extends ServiceProvider
22
{
23
    /**
24
     * @return void
25
     */
26
    public function boot(): void
27
    {
28
        $this->app->singleton(NavMatcher::class, function (Container $app) {
29
            $route = $this->route($app->make(Router::class));
30
31
            return new NavMatcher($route);
32
        });
33
    }
34
35
    /**
36
     * @param Router $router
37
     * @return Route
38
     */
39
    private function route(Router $router): Route
40
    {
41
        $route  = $router->current();
42
43
        if ($route === null) {
44
            $route = $router->get('/');
45
        }
46
47
        return $route;
48
    }
49
}
50