Completed
Push — master ( 42ecc4...ea2938 )
by Elf
05:23
created

RouteServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 80
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 10 1
A map() 0 47 2
1
<?php
2
3
namespace App\Providers;
4
5
use Illuminate\Support\Facades\Route;
6
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
7
8
class RouteServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * This namespace is applied to your controller routes.
12
     *
13
     * In addition, it is set as the URL generator's root namespace.
14
     *
15
     * @var string
16
     */
17
    protected $namespace = 'App\Http\Controllers';
18
19
    /**
20
     * Define your route model bindings, pattern filters, etc.
21
     *
22
     * @return void
23
     */
24 1
    public function boot()
25
    {
26 1
        $this->pattern('id', '[0-9]+');
1 ignored issue
show
Documentation Bug introduced by
The method pattern does not exist on object<App\Providers\RouteServiceProvider>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
27
28
        $this->bind('admin_user', function ($value) {
1 ignored issue
show
Documentation Bug introduced by
The method bind does not exist on object<App\Providers\RouteServiceProvider>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
29
            return \App\Models\AdminUser::find($value);
30 1
        });
31
32 1
        parent::boot();
33 1
    }
34
35
    /**
36
     * Define the routes for the application.
37
     *
38
     * @return void
39
     */
40 1
    public function map()
41
    {
42
        // Defines all routes in format: `identifier => attributes`.
43
        // If there is no "namespace" in attributes, the default namespace will be `$this->namespace.'\\'.studly_case($identifier)`.
44
        // The routes definitions will be placed in file "routes/{$identifer}.php".
45
        $routes = [
46
            'global' => [
47
                'namespace' => '',
48 1
            ],
49
50
            'site' => [
51 1
                'domain' => config('app.domains.site'),
52 1
                'middleware' => 'web',
53
            ],
54
55
            'admin' => [
56 1
                'domain' => config('app.domains.admin'),
57 1
                'middleware' => 'web',
58
            ],
59
60
            'api' => [
61 1
                'domain' => config('app.domains.api'),
62 1
                'middleware' => 'api',
63
            ],
64
65
            'api-web' => [
66 1
                'domain' => config('app.domains.site'),
67 1
                'prefix' => 'api',
68 1
                'namespace' => 'Site',
69
                'middleware' => ['web', 'api.client'],
70
            ],
71
        ];
72
73 1
        foreach ($routes as $identifier => $attributes) {
74 1
            $attributes['namespace'] = rtrim(
75 1
                $this->namespace.'\\'.studly_case(array_get($attributes, 'namespace', $identifier)),
76 1
                '\\'
77
            );
78
79 1
            Route::group(
80
                $attributes,
81 1
                function ($router) use ($identifier) {
82 1
                    require base_path('routes/'.$identifier.'.php');
83 1
                }
84
            );
85
        }
86 1
    }
87
}
88