Skip to content

Commit 43e2b61

Browse files
authored
Merge pull request #5 from scify/sonarqube_fixes
Fixed issues from SonarQube
2 parents 9ed75c3 + 043c3b2 commit 43e2b61

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+165
-144
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Exceptions;
6+
7+
use Exception;
8+
9+
class PermissionConfigurationException extends Exception {
10+
public static function configNotLoaded(): self {
11+
return new self('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
12+
}
13+
14+
public static function teamForeignKeyNotLoaded(): self {
15+
return new self('Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.');
16+
}
17+
18+
public static function configNotFoundForDown(): self {
19+
return new self('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.');
20+
}
21+
}

app/Http/Middleware/HandleInertiaRequests.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ class HandleInertiaRequests extends Middleware {
2020
*/
2121
protected $rootView = 'app';
2222

23-
/**
24-
* Determines the current asset version.
25-
*
26-
* @see https://inertiajs.com/asset-versioning
27-
*/
28-
public function version(Request $request): ?string {
29-
return parent::version($request);
30-
}
31-
3223
/**
3324
* Define the props that are shared by default.
3425
*

app/Policies/UserPolicy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function viewAny(User $user): bool {
1313
return $user->can(PermissionsEnum::VIEW_USERS->value);
1414
}
1515

16-
public function view(User $user, User $model): bool {
16+
public function view(User $user): bool {
1717
return $user->can(PermissionsEnum::VIEW_USERS->value);
1818
}
1919

@@ -49,7 +49,7 @@ public function delete(User $user, User $model): bool {
4949
return $user->can(PermissionsEnum::DELETE_USERS->value);
5050
}
5151

52-
public function restore(User $user, User $model): bool {
52+
public function restore(User $user): bool {
5353
return $user->can(PermissionsEnum::RESTORE_USERS->value);
5454
}
5555
}

config/database.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Illuminate\Support\Str;
66

7+
$DEFAULT_HOST = '127.0.0.1';
8+
79
return [
810

911
/*
@@ -47,7 +49,7 @@
4749
'mysql' => [
4850
'driver' => 'mysql',
4951
'url' => env('DB_URL'),
50-
'host' => env('DB_HOST', '127.0.0.1'),
52+
'host' => env('DB_HOST', $DEFAULT_HOST),
5153
'port' => env('DB_PORT', '3306'),
5254
'database' => env('DB_DATABASE', 'laravel'),
5355
'username' => env('DB_USERNAME', 'root'),
@@ -67,7 +69,7 @@
6769
'mariadb' => [
6870
'driver' => 'mariadb',
6971
'url' => env('DB_URL'),
70-
'host' => env('DB_HOST', '127.0.0.1'),
72+
'host' => env('DB_HOST', $DEFAULT_HOST),
7173
'port' => env('DB_PORT', '3306'),
7274
'database' => env('DB_DATABASE', 'laravel'),
7375
'username' => env('DB_USERNAME', 'root'),
@@ -87,7 +89,7 @@
8789
'pgsql' => [
8890
'driver' => 'pgsql',
8991
'url' => env('DB_URL'),
90-
'host' => env('DB_HOST', '127.0.0.1'),
92+
'host' => env('DB_HOST', $DEFAULT_HOST),
9193
'port' => env('DB_PORT', '5432'),
9294
'database' => env('DB_DATABASE', 'laravel'),
9395
'username' => env('DB_USERNAME', 'root'),
@@ -155,7 +157,7 @@
155157

156158
'default' => [
157159
'url' => env('REDIS_URL'),
158-
'host' => env('REDIS_HOST', '127.0.0.1'),
160+
'host' => env('REDIS_HOST', $DEFAULT_HOST),
159161
'username' => env('REDIS_USERNAME'),
160162
'password' => env('REDIS_PASSWORD'),
161163
'port' => env('REDIS_PORT', '6379'),
@@ -164,7 +166,7 @@
164166

165167
'cache' => [
166168
'url' => env('REDIS_URL'),
167-
'host' => env('REDIS_HOST', '127.0.0.1'),
169+
'host' => env('REDIS_HOST', $DEFAULT_HOST),
168170
'username' => env('REDIS_USERNAME'),
169171
'password' => env('REDIS_PASSWORD'),
170172
'port' => env('REDIS_PORT', '6379'),

config/logging.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Monolog\Handler\SyslogUdpHandler;
88
use Monolog\Processor\PsrLogMessageProcessor;
99

10+
$DEFAULT_LOG_PATH = 'logs/laravel.log';
11+
1012
return [
1113

1214
/*
@@ -62,14 +64,14 @@
6264

6365
'single' => [
6466
'driver' => 'single',
65-
'path' => storage_path('logs/laravel.log'),
67+
'path' => storage_path($DEFAULT_LOG_PATH),
6668
'level' => env('LOG_LEVEL', 'debug'),
6769
'replace_placeholders' => true,
6870
],
6971

7072
'daily' => [
7173
'driver' => 'daily',
72-
'path' => storage_path('logs/laravel.log'),
74+
'path' => storage_path($DEFAULT_LOG_PATH),
7375
'level' => env('LOG_LEVEL', 'debug'),
7476
'days' => env('LOG_DAILY_DAYS', 14),
7577
'replace_placeholders' => true,
@@ -126,7 +128,7 @@
126128
],
127129

128130
'emergency' => [
129-
'path' => storage_path('logs/laravel.log'),
131+
'path' => storage_path($DEFAULT_LOG_PATH),
130132
],
131133

132134
],

database/migrations/2025_03_19_061321_create_permission_tables.php

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

3+
use App\Exceptions\PermissionConfigurationException;
34
use Illuminate\Database\Migrations\Migration;
45
use Illuminate\Database\Schema\Blueprint;
56
use Illuminate\Support\Facades\Schema;
@@ -8,6 +9,7 @@
89
/**
910
* Run the migrations.
1011
*/
12+
// NOSONAR
1113
public function up(): void {
1214
$teams = config('permission.teams');
1315
$tableNames = config('permission.table_names');
@@ -16,10 +18,10 @@ public function up(): void {
1618
$pivotPermission = $columnNames['permission_pivot_key'] ?? 'permission_id';
1719

1820
if (empty($tableNames)) {
19-
throw new \Exception('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
21+
throw PermissionConfigurationException::configNotLoaded();
2022
}
2123
if ($teams && empty($columnNames['team_foreign_key'] ?? null)) {
22-
throw new \Exception('Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.');
24+
throw PermissionConfigurationException::teamForeignKeyNotLoaded();
2325
}
2426

2527
Schema::create($tableNames['permissions'], static function (Blueprint $table) {
@@ -132,7 +134,7 @@ public function down(): void {
132134
$tableNames = config('permission.table_names');
133135

134136
if (empty($tableNames)) {
135-
throw new \Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.');
137+
throw PermissionConfigurationException::configNotFoundForDown();
136138
}
137139

138140
Schema::drop($tableNames['role_has_permissions']);

database/seeders/RolesAndPermissionsSeeder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function run(): void {
3434
// create roles using RolesEnum
3535
$admin_role = Role::firstOrCreate(['name' => RolesEnum::ADMINISTRATOR->value, 'guard_name' => 'web']);
3636
$user_manager_role = Role::firstOrCreate(['name' => RolesEnum::USER_MANAGER->value, 'guard_name' => 'web']);
37-
$registered_user_role = Role::firstOrCreate(['name' => RolesEnum::REGISTERED_USER->value, 'guard_name' => 'web']);
37+
Role::firstOrCreate(['name' => RolesEnum::REGISTERED_USER->value, 'guard_name' => 'web']);
3838
// flush cache after creating roles and permissions
3939
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
4040

resources/js/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createRoot } from 'react-dom/client';
55
import { initializeTheme } from './hooks/use-appearance';
66

77
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
8-
const appName = import.meta.env.VITE_APP_NAME || 'Laravel';
8+
const appName = import.meta.env.VITE_APP_NAME ?? 'Laravel';
99

1010
createInertiaApp({
1111
title: (title) => `${title} - ${appName}`,

resources/js/components/app-content.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ interface AppContentProps extends React.ComponentProps<'main'> {
55
variant?: 'header' | 'sidebar';
66
}
77

8-
export function AppContent({ variant = 'header', children, ...props }: AppContentProps) {
8+
export function AppContent({ variant = 'header', children, ...props }: Readonly<AppContentProps>) {
99
if (variant === 'sidebar') {
1010
return <SidebarInset {...props}>{children}</SidebarInset>;
1111
}

resources/js/components/app-header.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ interface AppHeaderProps {
5252
breadcrumbs?: BreadcrumbItem[];
5353
}
5454

55-
export function AppHeader({ breadcrumbs = [] }: AppHeaderProps) {
55+
export function AppHeader({ breadcrumbs = [] }: Readonly<AppHeaderProps>) {
5656
const page = usePage<SharedData>();
5757
const { auth } = page.props;
5858
const getInitials = useInitials();
@@ -136,9 +136,9 @@ export function AppHeader({ breadcrumbs = [] }: AppHeaderProps) {
136136
<div className="ml-6 hidden h-full items-center space-x-6 lg:flex">
137137
<NavigationMenu className="flex h-full items-stretch">
138138
<NavigationMenuList className="flex h-full items-stretch space-x-2">
139-
{mainNavItems.map((item, index) => (
139+
{mainNavItems.map((item) => (
140140
<NavigationMenuItem
141-
key={index}
141+
key={item.href || item.title}
142142
className="relative flex h-full items-center"
143143
>
144144
<Link

0 commit comments

Comments
 (0)