Skip to content

Commit f15b3a0

Browse files
committed
Perbaiki struktur kode dan tambahkan komentar di beberapa file:
- **UserController.php**: Memindahkan komentar untuk membersihkan cache pengguna (baris 75, 146, 167) agar lebih rapi. - **NewPasswordController.php** dan **PasswordResetLinkController.php**: Menambahkan baris kosong setelah konstruktor (baris 21). - **HandleInertiaRequests.php**: Menghapus komentar yang tidak perlu (baris 21-23). - **User.php**: Memperbaiki komentar dan format kode di beberapa bagian (baris 32-50, 60-68). - **CacheService.php**: Menghapus parameter yang tidak perlu dari komentar (baris 33-39). - **ImageService.php**: Memperbaiki komentar untuk menjelaskan akses langsung ke indeks MIME (baris 239). - **helpers.php**: Menghapus komentar yang tidak perlu (baris 23-25). - **app.php**: Menghapus baris yang tidak perlu (baris 3-5). - **CreateUserModal.tsx** dan **EditUserModal.tsx**: Memperbaiki format kode dan menambahkan baris baru untuk kejelasan (baris 79, 99, 453). - **Index.tsx**: Memperbaiki format kode untuk kejelasan (baris 121). - **ShowUserModal.tsx**: Menghapus import yang tidak digunakan (baris 9). - **UserAvatarUpdateTest.php** dan **UserAvatarUploadNegativeTest.php**: Memperbaiki format kode untuk konsistensi (baris 29, 44, 58). - **AuthorizationTest.php**: Memperbaiki komentar dan mengubah rute pengujian untuk keamanan (baris 10, 80, 90). - **CacheHelperTest.php**: Menghapus baris kosong yang tidak perlu (baris 23). ✨💻
1 parent 8371608 commit f15b3a0

17 files changed

Lines changed: 71 additions & 56 deletions

app/Http/Controllers/Admin/UserController.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
use App\Http\Requests\Admin\Users\StoreUserRequest;
77
use App\Http\Requests\Admin\Users\UpdateUserRequest;
88
use App\Models\User;
9-
use App\Services\ImageService;
109
use App\Services\CacheService;
11-
use Illuminate\Support\Facades\Log;
10+
use App\Services\ImageService;
1211
use Illuminate\Http\Request;
12+
use Illuminate\Support\Facades\Log;
1313
use Inertia\Inertia;
1414

1515
class UserController extends Controller
@@ -75,8 +75,8 @@ public function store(StoreUserRequest $request)
7575

7676
User::create($data);
7777

78-
// Clear users list cache to show fresh data
79-
$this->cacheService->clearUsersList();
78+
// Clear users list cache to show fresh data
79+
$this->cacheService->clearUsersList();
8080

8181
return redirect()->route('admin.users.index')->with('success', 'User created successfully.');
8282
}
@@ -146,8 +146,8 @@ public function update(UpdateUserRequest $request, User $user)
146146

147147
$user->update($data);
148148

149-
// Clear users list cache keys (tags or explicit keys depending on driver)
150-
$this->cacheService->clearUsersList();
149+
// Clear users list cache keys (tags or explicit keys depending on driver)
150+
$this->cacheService->clearUsersList();
151151

152152
return redirect()->route('admin.users.index')->with('success', 'User updated successfully.');
153153
}
@@ -167,8 +167,8 @@ public function destroy(User $user)
167167

168168
$user->delete();
169169

170-
// Clear users list cache keys
171-
$this->cacheService->clearUsersList();
170+
// Clear users list cache keys
171+
$this->cacheService->clearUsersList();
172172

173173
return redirect()->route('admin.users.index')->with('success', 'User deleted successfully.');
174174
}

app/Http/Controllers/Auth/NewPasswordController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class NewPasswordController extends Controller
2121
* Create a new controller instance.
2222
*/
2323
public function __construct(private readonly SecurityLogger $securityLogger) {}
24+
2425
/**
2526
* Show the password reset page.
2627
*/

app/Http/Controllers/Auth/PasswordResetLinkController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class PasswordResetLinkController extends Controller
1616
* Create a new controller instance.
1717
*/
1818
public function __construct(private readonly SecurityLogger $securityLogger) {}
19+
1920
/**
2021
* Show the password reset link request page.
2122
*/

app/Http/Middleware/HandleInertiaRequests.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class HandleInertiaRequests extends Middleware
2121
/**
2222
* Determine the current asset version.
2323
* Dynamically select the root view based on the request path.
24-
*
25-
* @return string
2624
*/
2725
public function rootView(Request $request): string
2826
{

app/Models/User.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class User extends Authenticatable
3232

3333
/**
3434
* Get the user's image URL with fallback to default avatar.
35-
*
35+
*
3636
* If user has no image, return default user.svg from public folder.
3737
* If user has image, return full storage URL.
38-
*
38+
*
3939
* Note: Image is stored as 'users/avatar-xxx.webp' in database,
4040
* so we prepend 'storage/' to get full public URL.
4141
*/
@@ -50,7 +50,7 @@ public function getImageUrlAttribute(): string
5050
// Build the correct public URL: /storage/users/{filename}
5151
$filename = ltrim($this->attributes['image'], '/');
5252

53-
return asset('storage/users/' . $filename);
53+
return asset('storage/users/'.$filename);
5454
}
5555

5656
/**
@@ -60,15 +60,15 @@ public function getImageUrlAttribute(): string
6060
public static function generateMemberNumber(): string
6161
{
6262
for ($i = 0; $i < 10; $i++) {
63-
$candidate = 'M' . str_pad((string) random_int(1, 9999), 4, '0', STR_PAD_LEFT);
63+
$candidate = 'M'.str_pad((string) random_int(1, 9999), 4, '0', STR_PAD_LEFT);
6464

6565
if (! self::where('member_number', $candidate)->exists()) {
6666
return $candidate;
6767
}
6868
}
6969

7070
// Fallback: unlikely collision case
71-
return 'M' . strtoupper(bin2hex(random_bytes(3)));
71+
return 'M'.strtoupper(bin2hex(random_bytes(3)));
7272
}
7373

7474
protected $hidden = [

app/Services/CacheService.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ public function usersListKey(int $page, int $perPage): string
3333
/**
3434
* Remember users list using tags when available, otherwise plain remember.
3535
*
36-
* @param int $page
37-
* @param int $perPage
3836
* @param int|\DateTimeInterface|\DateInterval $ttl
39-
* @param \Closure $callback
4037
* @return mixed
4138
*/
4239
public function rememberUsersList(int $page, int $perPage, $ttl, Closure $callback)
@@ -59,6 +56,7 @@ public function clearUsersList(): void
5956
{
6057
if ($this->supportsTags()) {
6158
Cache::tags(['users'])->flush();
59+
6260
return;
6361
}
6462

app/Services/ImageService.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,10 @@ protected function isValidImage(UploadedFile $file): bool
239239
}
240240

241241
// Verify MIME type from actual file content matches declared MIME
242-
$actualMimeType = $imageInfo['mime'] ?? null;
242+
// getimagesize() returned a non-false value above, so the 'mime' index
243+
// is guaranteed to exist for valid images. Use direct access to satisfy
244+
// static analysis (PHPStan) while preserving runtime behavior.
245+
$actualMimeType = $imageInfo['mime'];
243246
if (! in_array($actualMimeType, $allowedMimes, true)) {
244247
\Log::warning('File rejected: Content MIME type mismatch', [
245248
'declared_mime' => $file->getMimeType(),

app/helpers.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
* if (cache_service()->supportsTags()) {
2424
* // Use tag-based operations
2525
* }
26-
*
27-
* @return \App\Services\CacheService
2826
*/
2927
function cache_service(): CacheService
3028
{

bootstrap/app.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
use App\Http\Middleware\HandleAppearance;
44
use App\Http\Middleware\HandleInertiaRequests;
55
use App\Http\Middleware\SecurityHeaders;
6+
use Illuminate\Cache\RateLimiting\Limit;
67
use Illuminate\Foundation\Application;
78
use Illuminate\Foundation\Configuration\Exceptions;
89
use Illuminate\Foundation\Configuration\Middleware;
910
use Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets;
11+
use Illuminate\Http\Request;
1012
use Illuminate\Support\Facades\RateLimiter;
1113
use Illuminate\Support\Facades\Route;
12-
use Illuminate\Http\Request;
13-
use Illuminate\Cache\RateLimiting\Limit;
1414

1515
return Application::configure(basePath: dirname(__DIR__))
1616
->withRouting(

resources/js/pages/admin/users/CreateUserModal.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import {
1818
SelectValue,
1919
} from '@/components/ui/select';
2020
import { useForm } from '@inertiajs/react';
21-
import { FormEventHandler, useRef, useState, useEffect } from 'react';
21+
import { UploadCloud, X } from 'lucide-react';
22+
import { FormEventHandler, useEffect, useRef, useState } from 'react';
2223
import { toast } from 'sonner';
23-
import { UploadCloud, X, RotateCw } from 'lucide-react';
2424

2525
interface CreateUserModalProps {
2626
isOpen: boolean;
@@ -79,9 +79,16 @@ export default function CreateUserModal({
7979
const handleFileChange = (file: File | null) => {
8080
if (!file) return;
8181

82-
const validTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
82+
const validTypes = [
83+
'image/jpeg',
84+
'image/png',
85+
'image/gif',
86+
'image/webp',
87+
];
8388
if (!validTypes.includes(file.type)) {
84-
toast.error('Please upload a valid image file (JPG, PNG, GIF, WebP)');
89+
toast.error(
90+
'Please upload a valid image file (JPG, PNG, GIF, WebP)',
91+
);
8592
return;
8693
}
8794

@@ -453,7 +460,8 @@ export default function CreateUserModal({
453460
</span>
454461
</Label>
455462
<p className="text-xs text-gray-500 dark:text-gray-400">
456-
JPG, PNG, GIF, WebP • Max 10MB • 200x200px
463+
JPG, PNG, GIF, WebP • Max 10MB •
464+
200x200px
457465
</p>
458466
</div>
459467
)}

0 commit comments

Comments
 (0)