chore: code refactor via rector

This commit is contained in:
idevakk
2025-11-14 02:01:01 -08:00
parent 90ab79b3a2
commit ae795880ed
148 changed files with 1520 additions and 1486 deletions

View File

@@ -2,13 +2,15 @@
namespace App\Filament\Resources;
use BackedEnum;
use UnitEnum;
use Illuminate\Support\Facades\DB;
use App\Filament\Resources\UserResource\Pages\CreateUser;
use App\Filament\Resources\UserResource\Pages\EditUser;
use App\Filament\Resources\UserResource\Pages\ListUsers;
use App\Filament\Resources\UserResource\RelationManagers\LogsRelationManager;
use App\Filament\Resources\UserResource\RelationManagers\UsageLogsRelationManager;
use App\Models\User;
use DB;
use Exception;
use Filament\Actions\BulkAction;
use Filament\Actions\BulkActionGroup;
@@ -31,9 +33,9 @@ class UserResource extends Resource
{
protected static ?string $model = User::class;
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-users';
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-users';
protected static string|\UnitEnum|null $navigationGroup = 'Admin';
protected static string|UnitEnum|null $navigationGroup = 'Admin';
public static function form(Schema $schema): Schema
{
@@ -50,7 +52,7 @@ class UserResource extends Resource
TextInput::make('email_verified_at')
->label('Email Verification Status')
->disabled()
->formatStateUsing(fn ($record) => $record->email_verified_at ?? ''
->formatStateUsing(fn ($record): string => $record->email_verified_at ?? ''
? 'Verified at '.$record->email_verified_at->toDateTimeString()
: 'Not Verified')
->helperText('Shows whether the user has verified their email address.'),
@@ -96,22 +98,20 @@ class UserResource extends Resource
->falseIcon('heroicon-o-x-circle')
->trueColor('success')
->falseColor('danger')
->getStateUsing(fn ($record) => ! is_null($record->email_verified_at))
->getStateUsing(fn ($record): bool => ! is_null($record->email_verified_at))
->sortable(),
BadgeColumn::make('level')
->label('User Level')
->getStateUsing(function ($record) {
return match ($record->level) {
0 => 'Normal User',
1 => 'Banned',
9 => 'Super Admin',
default => 'Unknown', // In case some invalid level exists
};
->getStateUsing(fn($record): string => match ($record->level) {
0 => 'Normal User',
1 => 'Banned',
9 => 'Super Admin',
default => 'Unknown', // In case some invalid level exists
})
->colors([
'success' => fn ($state) => $state === 'Normal User',
'danger' => fn ($state) => $state === 'Banned',
'warning' => fn ($state) => $state === 'Super Admin',
'success' => fn ($state): bool => $state === 'Normal User',
'danger' => fn ($state): bool => $state === 'Banned',
'warning' => fn ($state): bool => $state === 'Super Admin',
])
->sortable(),
TextColumn::make('stripe_id')->label('Stripe ID')->copyable(),
@@ -126,14 +126,14 @@ class UserResource extends Resource
'subscribed' => 'Has Active Subscription',
'not_subscribed' => 'No Active Subscription',
])
->query(function ($query, array $data) {
->query(function ($query, array $data): void {
if ($data['value'] === 'subscribed') {
$query->whereHas('subscriptions', function ($query) {
$query->whereHas('subscriptions', function ($query): void {
$query->where('stripe_status', 'active')
->orWhere('stripe_status', 'trialing');
});
} elseif ($data['value'] === 'not_subscribed') {
$query->whereDoesntHave('subscriptions', function ($query) {
$query->whereDoesntHave('subscriptions', function ($query): void {
$query->where('stripe_status', 'active')
->orWhere('stripe_status', 'trialing');
});
@@ -145,7 +145,7 @@ class UserResource extends Resource
'verified' => 'Verified',
'not_verified' => 'Not Verified',
])
->query(function ($query, array $data) {
->query(function ($query, array $data): void {
if ($data['value'] === 'verified') {
$query->whereNotNull('email_verified_at');
} elseif ($data['value'] === 'not_verified') {
@@ -161,12 +161,10 @@ class UserResource extends Resource
DeleteBulkAction::make(),
BulkAction::make('updateLevel')
->label('Update User Level')
->action(function (Collection $records, array $data) {
->action(function (Collection $records, array $data): void {
$newLevel = $data['new_level'];
if ($newLevel === 9) {
throw new Exception('User level cannot be 9 or higher.');
}
throw_if($newLevel === 9, Exception::class, 'User level cannot be 9 or higher.');
DB::table('users')
->whereIn('id', $records->pluck('id'))