chore: code refactor via rector
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use BackedEnum;
|
||||
use UnitEnum;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use App\Models\ActivationKey;
|
||||
use App\Models\Plan;
|
||||
use Filament\Actions\BulkAction;
|
||||
@@ -19,17 +23,16 @@ use Filament\Tables\Filters\SelectFilter;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Response;
|
||||
use Str;
|
||||
|
||||
class GenerateActivationKeys extends Page implements HasForms, HasTable
|
||||
{
|
||||
use InteractsWithForms, InteractsWithTable;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-key';
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-key';
|
||||
|
||||
protected string $view = 'filament.pages.generate-activation-keys';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Admin';
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Admin';
|
||||
|
||||
protected static ?string $title = 'Activation Keys';
|
||||
|
||||
@@ -59,13 +62,13 @@ class GenerateActivationKeys extends Page implements HasForms, HasTable
|
||||
];
|
||||
}
|
||||
|
||||
public function generate()
|
||||
public function generate(): void
|
||||
{
|
||||
$data = $this->form->getState();
|
||||
$plan = Plan::findOrFail($data['plan_id']);
|
||||
$plan = Plan::query()->findOrFail($data['plan_id']);
|
||||
|
||||
for ($i = 0; $i < $data['quantity']; $i++) {
|
||||
ActivationKey::create([
|
||||
ActivationKey::query()->create([
|
||||
'price_id' => $plan->pricing_id,
|
||||
'activation_key' => strtoupper('Z'.Str::random(16)),
|
||||
'is_activated' => false,
|
||||
@@ -99,8 +102,8 @@ class GenerateActivationKeys extends Page implements HasForms, HasTable
|
||||
|
||||
TextColumn::make('billing_interval')
|
||||
->label('Interval')
|
||||
->getStateUsing(function ($record) {
|
||||
$isMonthly = Plan::where('pricing_id', $record->price_id)->value('monthly_billing');
|
||||
->getStateUsing(function ($record): string {
|
||||
$isMonthly = Plan::query()->where('pricing_id', $record->price_id)->value('monthly_billing');
|
||||
|
||||
return $isMonthly ? 'Monthly' : 'Yearly';
|
||||
}),
|
||||
@@ -121,7 +124,7 @@ class GenerateActivationKeys extends Page implements HasForms, HasTable
|
||||
SelectFilter::make('price_id')
|
||||
->label('Plan')
|
||||
->options(
|
||||
Plan::pluck('name', 'pricing_id')
|
||||
Plan::query()->pluck('name', 'pricing_id')
|
||||
),
|
||||
];
|
||||
}
|
||||
@@ -130,13 +133,13 @@ class GenerateActivationKeys extends Page implements HasForms, HasTable
|
||||
{
|
||||
return [
|
||||
BulkAction::make('Download Keys')
|
||||
->action(fn (Collection $records) => $this->downloadKeys($records))
|
||||
->action(fn (Collection $records): BinaryFileResponse => $this->downloadKeys($records))
|
||||
->deselectRecordsAfterCompletion()
|
||||
->requiresConfirmation(),
|
||||
];
|
||||
}
|
||||
|
||||
public function downloadKeys(Collection $records)
|
||||
public function downloadKeys(Collection $records): BinaryFileResponse
|
||||
{
|
||||
$text = $records->pluck('activation_key')->implode("\n");
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use BackedEnum;
|
||||
use UnitEnum;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use App\Models\Setting;
|
||||
use App\Models\ZEmail;
|
||||
use Artisan;
|
||||
use Exception;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
use Filament\Forms\Components\KeyValue;
|
||||
@@ -25,17 +27,17 @@ class Settings extends Page implements HasForms
|
||||
|
||||
public ?array $data = [];
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-cog-6-tooth';
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-cog-6-tooth';
|
||||
|
||||
protected string $view = 'filament.pages.settings';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Web Master';
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Web Master';
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$user = auth()->user();
|
||||
$auth_email = $user->email;
|
||||
$setting = Setting::where('app_admin', $auth_email)->first();
|
||||
$setting = Setting::query()->where('app_admin', $auth_email)->first();
|
||||
|
||||
if ($setting) {
|
||||
$imapSettings = $setting->imap_settings ?? [];
|
||||
@@ -50,7 +52,7 @@ class Settings extends Page implements HasForms
|
||||
]);
|
||||
|
||||
$this->applyDefaults($configurationSettings, [
|
||||
'cron_password' => fn () => $this->generateRandomString(20),
|
||||
'cron_password' => fn (): string => $this->generateRandomString(20),
|
||||
'date_format' => 'd M Y h:i A',
|
||||
'after_last_email_delete' => 'redirect_to_homepage',
|
||||
]);
|
||||
@@ -68,9 +70,7 @@ class Settings extends Page implements HasForms
|
||||
|
||||
foreach ($transformMap as $key => $subKey) {
|
||||
if (isset($configurationSettings[$key])) {
|
||||
$configurationSettings[$key] = array_map(function ($value) use ($subKey) {
|
||||
return [$subKey => $value];
|
||||
}, $configurationSettings[$key]);
|
||||
$configurationSettings[$key] = array_map(fn($value): array => [$subKey => $value], $configurationSettings[$key]);
|
||||
}
|
||||
}
|
||||
$this->form->fill([
|
||||
@@ -376,12 +376,11 @@ class Settings extends Page implements HasForms
|
||||
$data = $this->form->getState();
|
||||
if (! $this->testIMAP($data['imap_settings'])) {
|
||||
return;
|
||||
} else {
|
||||
Notification::make()
|
||||
->title('IMAP Connection Successful')
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
Notification::make()
|
||||
->title('IMAP Connection Successful')
|
||||
->success()
|
||||
->send();
|
||||
foreach ([
|
||||
'protocol' => 'imap',
|
||||
'default_account' => 'default',
|
||||
@@ -410,7 +409,7 @@ class Settings extends Page implements HasForms
|
||||
}
|
||||
}
|
||||
|
||||
$setting = Setting::where('id', 1)->first();
|
||||
$setting = Setting::query()->where('id', 1)->first();
|
||||
|
||||
$user = auth()->user();
|
||||
$auth_email = $user->email;
|
||||
@@ -447,7 +446,7 @@ class Settings extends Page implements HasForms
|
||||
'configuration_settings' => $data['configuration_settings'],
|
||||
'ads_settings' => $data['ads_settings'],
|
||||
];
|
||||
$create_res = Setting::create(array_merge($data));
|
||||
$create_res = Setting::query()->create(array_merge($data));
|
||||
|
||||
if ($create_res) {
|
||||
Notification::make()
|
||||
@@ -464,13 +463,13 @@ class Settings extends Page implements HasForms
|
||||
}
|
||||
}
|
||||
|
||||
private function generateRandomString($length = 10): string
|
||||
private function generateRandomString(int $length = 10): string
|
||||
{
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
$randomString .= $characters[random_int(0, $charactersLength - 1)];
|
||||
}
|
||||
|
||||
return $randomString;
|
||||
|
||||
Reference in New Issue
Block a user