scriptotek /
bibrex
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Providers; |
||
| 4 | |||
| 5 | use App\Item; |
||
| 6 | use App\Loan; |
||
| 7 | use App\Notifications\ExtendedDatabaseNotification; |
||
| 8 | use App\Thing; |
||
| 9 | use App\User; |
||
| 10 | use Illuminate\Support\Facades\Route; |
||
| 11 | use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; |
||
| 12 | |||
| 13 | class RouteServiceProvider extends ServiceProvider |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * This namespace is applied to your controller routes. |
||
| 17 | * |
||
| 18 | * In addition, it is set as the URL generator's root namespace. |
||
| 19 | * |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $namespace = 'App\Http\Controllers'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Define your route model bindings, pattern filters, etc. |
||
| 26 | * |
||
| 27 | * @return void |
||
| 28 | */ |
||
| 29 | public function boot() |
||
| 30 | { |
||
| 31 | Route::pattern('user', '([0-9]+|_new)'); |
||
| 32 | Route::pattern('item', '([0-9]+|_new)'); |
||
| 33 | Route::pattern('thing', '([0-9]+|_new)'); |
||
| 34 | |||
| 35 | Route::pattern('library', '[0-9]+'); |
||
| 36 | Route::pattern('user1', '[0-9]+'); |
||
| 37 | Route::pattern('user2', '[0-9]+'); |
||
| 38 | Route::pattern('loan', '[0-9]+'); |
||
| 39 | Route::pattern('reminder', '[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
|
|||
| 51 | }); |
||
| 52 | |||
| 53 | Route::bind('item', function ($value) { |
||
| 54 | return $value == '_new' |
||
| 55 | ? new Item([ 'library_id' => \Auth::user()->id ]) |
||
| 56 | : Item::withTrashed()->find($value) ?? abort(404); |
||
|
0 ignored issues
–
show
Are you sure the usage of
abort(404) is correct as it seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. 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
Are you sure the usage of
abort(404) is correct as it seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||
| 63 | }); |
||
| 64 | |||
| 65 | Route::bind('loan', function ($value) { |
||
| 66 | return Loan::withTrashed()->find($value) ?? abort(404); |
||
|
0 ignored issues
–
show
Are you sure the usage of
abort(404) is correct as it seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||
| 67 | }); |
||
| 68 | |||
| 69 | Route::bind('notification', function ($value) { |
||
| 70 | return ExtendedDatabaseNotification::with('loan') |
||
| 71 | ->find($value) ?? abort(404); |
||
|
0 ignored issues
–
show
Are you sure the usage of
abort(404) is correct as it seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||
| 72 | }); |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Define the routes for the application. |
||
| 77 | * |
||
| 78 | * @return void |
||
| 79 | */ |
||
| 80 | public function map() |
||
| 81 | { |
||
| 82 | $this->mapApiRoutes(); |
||
| 83 | |||
| 84 | $this->mapWebRoutes(); |
||
| 85 | |||
| 86 | $this->mapWebhooksRoutes(); |
||
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Define the "web" routes for the application. |
||
| 91 | * |
||
| 92 | * These routes all receive session state, CSRF protection, etc. |
||
| 93 | * |
||
| 94 | * @return void |
||
| 95 | */ |
||
| 96 | protected function mapWebRoutes() |
||
| 97 | { |
||
| 98 | Route::middleware('web') |
||
| 99 | ->namespace($this->namespace) |
||
| 100 | ->group(base_path('routes/web.php')); |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Define the "api" routes for the application. |
||
| 105 | * |
||
| 106 | * These routes are typically stateless. |
||
| 107 | * |
||
| 108 | * @return void |
||
| 109 | */ |
||
| 110 | protected function mapApiRoutes() |
||
| 111 | { |
||
| 112 | Route::prefix('api') |
||
| 113 | ->middleware('api') |
||
| 114 | ->namespace($this->namespace) |
||
| 115 | ->group(base_path('routes/api.php')); |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Define the "webhooks" routes for the application. |
||
| 120 | * |
||
| 121 | * These routes are typically stateless. |
||
| 122 | * |
||
| 123 | * @return void |
||
| 124 | */ |
||
| 125 | protected function mapWebhooksRoutes() |
||
| 126 | { |
||
| 127 | Route::prefix('webhooks') |
||
| 128 | ->middleware('webhooks') |
||
| 129 | ->namespace($this->namespace) |
||
| 130 | ->group(base_path('routes/webhooks.php')); |
||
| 131 | } |
||
| 132 | } |
||
| 133 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.