Skip to content

Commit d368795

Browse files
committed
Code cleaning
1 parent 01374d9 commit d368795

File tree

10 files changed

+22
-27
lines changed

10 files changed

+22
-27
lines changed

src/Composers/SidebarViewComposer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public function compose(View $view): void
1414
if (Gate::denies('read projects')) {
1515
return;
1616
}
17-
$view->offsetGet('sidebar')->group(__('Content'), function (SidebarGroup $group) {
17+
$view->offsetGet('sidebar')->group(__('Content'), function (SidebarGroup $group): void {
1818
$group->id = 'content';
1919
$group->weight = 30;
20-
$group->addItem(__('Projects'), function (SidebarItem $item) {
20+
$group->addItem(__('Projects'), function (SidebarItem $item): void {
2121
$item->id = 'projects';
2222
$item->icon = config('typicms.modules.projects.sidebar.icon');
2323
$item->weight = config('typicms.modules.projects.sidebar.weight');

src/Http/Controllers/AdminController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function create(): View
3232
$model = new Project();
3333

3434
return view('projects::admin.create')
35-
->with(compact('model'));
35+
->with(['model' => $model]);
3636
}
3737

3838
public function edit(Project $project): View

src/Http/Controllers/ApiController.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ public function index(Request $request): LengthAwarePaginator
1919
{
2020
$query = Project::query()
2121
->selectFields()
22-
->selectSub(ProjectCategory::select(column('title'))->whereColumn('category_id', 'project_categories.id'), 'category_name');
23-
$data = QueryBuilder::for($query)
22+
->selectSub(ProjectCategory::query()->select(column('title'))->whereColumn('category_id', 'project_categories.id'), 'category_name');
23+
24+
return QueryBuilder::for($query)
2425
->allowedSorts(['status_translated', 'date', 'title_translated', 'category_name'])
2526
->allowedFilters([
2627
AllowedFilter::custom('title', new FilterOr()),
2728
])
2829
->allowedIncludes(['image'])
2930
->paginate($request->integer('per_page'));
30-
31-
return $data;
3231
}
3332

3433
protected function updatePartial(Project $project, Request $request): void

src/Http/Controllers/CategoriesAdminController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function create(): View
2121
$model = new ProjectCategory();
2222

2323
return view('projects::admin.create-category')
24-
->with(compact('model'));
24+
->with(['model' => $model]);
2525
}
2626

2727
public function edit(ProjectCategory $category): View

src/Http/Controllers/CategoriesApiController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ class CategoriesApiController extends BaseApiController
1818
public function index(Request $request): LengthAwarePaginator
1919
{
2020
$query = ProjectCategory::query()->selectFields();
21-
$data = QueryBuilder::for($query)
21+
22+
return QueryBuilder::for($query)
2223
->allowedSorts(['status_translated', 'position', 'title_translated'])
2324
->allowedFilters([
2425
AllowedFilter::custom('title', new FilterOr()),
2526
])
2627
->allowedIncludes(['image'])
2728
->paginate($request->integer('per_page'));
28-
29-
return $data;
3029
}
3130

3231
protected function updatePartial(ProjectCategory $category, Request $request): void

src/Http/Controllers/PublicController.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function index(): View
1818
->get();
1919

2020
return view('projects::public.index')
21-
->with(compact('categories'));
21+
->with(['categories' => $categories]);
2222
}
2323

2424
public function indexOfCategory(?string $categorySlug = null): View
@@ -35,7 +35,7 @@ public function indexOfCategory(?string $categorySlug = null): View
3535
->get();
3636

3737
return view('projects::public.index-of-category')
38-
->with(compact('models', 'category'));
38+
->with(['models' => $models, 'category' => $category]);
3939
}
4040

4141
public function show(?string $categorySlug = null, ?string $slug = null): View
@@ -53,11 +53,9 @@ public function show(?string $categorySlug = null, ?string $slug = null): View
5353
])
5454
->whereSlugIs($slug)
5555
->firstOrFail();
56-
if ($category->id !== $model->category_id) {
57-
abort(404);
58-
}
56+
abort_if($category->id !== $model->category_id, 404);
5957

6058
return view('projects::public.show')
61-
->with(compact('model'));
59+
->with(['model' => $model]);
6260
}
6361
}

src/Models/Project.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected function casts(): array
9696

9797
public function url(?string $locale = null): string
9898
{
99-
$locale = $locale ?: app()->getLocale();
99+
$locale ??= app()->getLocale();
100100
$route = $locale . '::project';
101101
$slug = $this->translate('slug', $locale);
102102
$categorySlug = $this->category->translate('slug', $locale);

src/Models/ProjectCategory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function allForSelect(): array
7676

7777
public function url(?string $locale = null): string
7878
{
79-
$locale = $locale ?: app()->getLocale();
79+
$locale ??= app()->getLocale();
8080
$route = $locale . '::projects-category';
8181
$slug = $this->translate('slug', $locale);
8282

src/Providers/ModuleServiceProvider.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ public function boot(): void
4343
View::composer('core::admin._sidebar', SidebarViewComposer::class);
4444

4545
// A project have tags.
46-
Tag::resolveRelationUsing('projects', function ($tag) {
47-
return $tag->morphedByMany(Project::class, 'taggable');
48-
});
46+
Tag::resolveRelationUsing('projects', fn($tag) => $tag->morphedByMany(Project::class, 'taggable'));
4947

5048
// Add the page in the view.
51-
View::composer('projects::public.*', function ($view) {
49+
View::composer('projects::public.*', function ($view): void {
5250
$view->page = getPageLinkedToModule('projects');
5351
});
5452
}

src/routes/projects.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use TypiCMS\Modules\Core\Models\Page;
34
use Illuminate\Routing\Router;
45
use Illuminate\Support\Facades\Route;
56
use TypiCMS\Modules\Projects\Http\Controllers\AdminController;
@@ -11,11 +12,11 @@
1112
/*
1213
* Front office routes
1314
*/
14-
if ($page = getPageLinkedToModule('projects')) {
15+
if (($page = getPageLinkedToModule('projects')) instanceof Page) {
1516
$middleware = $page->private ? ['public', 'auth'] : ['public'];
1617
foreach (locales() as $lang) {
1718
if ($page->isPublished($lang) && $path = $page->path($lang)) {
18-
Route::middleware($middleware)->prefix($path)->name($lang . '::')->group(function (Router $router) {
19+
Route::middleware($middleware)->prefix($path)->name($lang . '::')->group(function (Router $router): void {
1920
$router->get('/', [PublicController::class, 'index'])->name('index-projects');
2021
$router->get('{category}', [PublicController::class, 'indexOfCategory'])->name('projects-category');
2122
$router->get('{category}/{slug}', [PublicController::class, 'show'])->name('project');
@@ -27,7 +28,7 @@
2728
/*
2829
* Admin routes
2930
*/
30-
Route::middleware('admin')->prefix('admin')->name('admin::')->group(function (Router $router) {
31+
Route::middleware('admin')->prefix('admin')->name('admin::')->group(function (Router $router): void {
3132
$router->get('projects', [AdminController::class, 'index'])->name('index-projects')->middleware('can:read projects');
3233
$router->get('projects/export', [AdminController::class, 'export'])->name('export-projects')->middleware('can:read projects');
3334
$router->get('projects/create', [AdminController::class, 'create'])->name('create-project')->middleware('can:create projects');
@@ -46,7 +47,7 @@
4647
/*
4748
* API routes
4849
*/
49-
Route::middleware(['api', 'auth:api'])->prefix('api')->group(function (Router $router) {
50+
Route::middleware(['api', 'auth:api'])->prefix('api')->group(function (Router $router): void {
5051
$router->get('projects', [ApiController::class, 'index'])->middleware('can:read projects');
5152
$router->patch('projects/{project}', [ApiController::class, 'updatePartial'])->middleware('can:update projects');
5253
$router->delete('projects/{project}', [ApiController::class, 'destroy'])->middleware('can:delete projects');

0 commit comments

Comments
 (0)