Passed
Push — master ( bc6228...d8a84b )
by Dan Michael O.
02:53
created

RouteServiceProvider::map()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Providers;
4
5
use App\Item;
6
use App\Loan;
7
use App\Thing;
8
use App\User;
9
use Illuminate\Support\Facades\Route;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Facades\Route was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
0 ignored issues
show
Bug introduced by
The type Illuminate\Foundation\Su...rs\RouteServiceProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
class RouteServiceProvider extends ServiceProvider
13
{
14
    /**
15
     * This namespace is applied to your controller routes.
16
     *
17
     * In addition, it is set as the URL generator's root namespace.
18
     *
19
     * @var string
20
     */
21
    protected $namespace = 'App\Http\Controllers';
22
23
    /**
24
     * Define your route model bindings, pattern filters, etc.
25
     *
26
     * @return void
27
     */
28
    public function boot()
29
    {
30
        Route::pattern('user', '([0-9]+|_new)');
31
        Route::pattern('item', '([0-9]+|_new)');
32
        Route::pattern('thing', '([0-9]+|_new)');
33
34
        Route::pattern('library', '[0-9]+');
35
        Route::pattern('user1', '[0-9]+');
36
        Route::pattern('user2', '[0-9]+');
37
        Route::pattern('loan', '[0-9]+');
38
        Route::pattern('reminder', '[0-9]+');
39
        Route::pattern('notification', '[0-9]+');
40
        Route::pattern('ip', '[0-9]+');
41
42
        parent::boot();
43
44
        Route::bind('thing', function ($value) {
45
            return $value == '_new'
46
                ? new Thing(['properties' => []])
47
                : Thing::withTrashed()
48
                    ->with('items.loans')
49
                    ->with('items.allLoans')
50
                    ->find($value) ?? abort(404);
0 ignored issues
show
Bug introduced by
The function abort was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
                    ->find($value) ?? /** @scrutinizer ignore-call */ abort(404);
Loading history...
51
        });
52
53
        Route::bind('item', function ($value) {
54
            return $value == '_new'
55
                ? new Item([ 'library_id' => \Auth::user()->id ])
0 ignored issues
show
Bug introduced by
The type Auth was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
56
                : Item::withTrashed()->find($value) ?? abort(404);
0 ignored issues
show
Bug introduced by
The function abort was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
                : Item::withTrashed()->find($value) ?? /** @scrutinizer ignore-call */ abort(404);
Loading history...
57
        });
58
59
        Route::bind('user', function ($value) {
60
            return $value == '_new'
61
                ? new User()
62
                : User::find($value) ?? abort(404);
0 ignored issues
show
Bug introduced by
The function abort was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

62
                : User::find($value) ?? /** @scrutinizer ignore-call */ abort(404);
Loading history...
63
        });
64
65
        Route::bind('loan', function ($value) {
66
            return Loan::withTrashed()->find($value) ?? abort(404);
0 ignored issues
show
Bug introduced by
The function abort was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
            return Loan::withTrashed()->find($value) ?? /** @scrutinizer ignore-call */ abort(404);
Loading history...
67
        });
68
    }
69
70
    /**
71
     * Define the routes for the application.
72
     *
73
     * @return void
74
     */
75
    public function map()
76
    {
77
        $this->mapApiRoutes();
78
79
        $this->mapWebRoutes();
80
81
        $this->mapWebhooksRoutes();
82
    }
83
84
    /**
85
     * Define the "web" routes for the application.
86
     *
87
     * These routes all receive session state, CSRF protection, etc.
88
     *
89
     * @return void
90
     */
91
    protected function mapWebRoutes()
92
    {
93
        Route::middleware('web')
94
             ->namespace($this->namespace)
95
             ->group(base_path('routes/web.php'));
0 ignored issues
show
Bug introduced by
The function base_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

95
             ->group(/** @scrutinizer ignore-call */ base_path('routes/web.php'));
Loading history...
96
    }
97
98
    /**
99
     * Define the "api" routes for the application.
100
     *
101
     * These routes are typically stateless.
102
     *
103
     * @return void
104
     */
105
    protected function mapApiRoutes()
106
    {
107
        Route::prefix('api')
108
             ->middleware('api')
109
             ->namespace($this->namespace)
110
             ->group(base_path('routes/api.php'));
0 ignored issues
show
Bug introduced by
The function base_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

110
             ->group(/** @scrutinizer ignore-call */ base_path('routes/api.php'));
Loading history...
111
    }
112
113
    /**
114
     * Define the "webhooks" routes for the application.
115
     *
116
     * These routes are typically stateless.
117
     *
118
     * @return void
119
     */
120
    protected function mapWebhooksRoutes()
121
    {
122
        Route::prefix('webhooks')
123
            ->middleware('webhooks')
124
            ->namespace($this->namespace)
125
            ->group(base_path('routes/webhooks.php'));
0 ignored issues
show
Bug introduced by
The function base_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

125
            ->group(/** @scrutinizer ignore-call */ base_path('routes/webhooks.php'));
Loading history...
126
    }
127
}
128