refactor: auto-refactor via rector

This commit is contained in:
idevakk
2025-10-02 22:37:58 +05:30
parent d3bf62375a
commit 28e36c47e3
5 changed files with 52 additions and 50 deletions

View File

@@ -124,9 +124,7 @@ class MailSettings extends AbstractPageSettings
]; ];
// Check for missing or empty required fields // Check for missing or empty required fields
$missingFields = collect($requiredFields)->filter(function ($field) use ($settings) { $missingFields = collect($requiredFields)->filter(fn($field): bool => empty($settings[$field]));
return empty($settings[$field]);
});
if ($missingFields->isNotEmpty()) { if ($missingFields->isNotEmpty()) {
Notification::make() Notification::make()
@@ -140,7 +138,7 @@ class MailSettings extends AbstractPageSettings
$transport = new \Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport( $transport = new \Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport(
$settings['mail_host'], $settings['mail_host'],
(int) $settings['mail_port'], (int) $settings['mail_port'],
strtolower($settings['mail_encryption']) === 'ssl' strtolower((string) $settings['mail_encryption']) === 'ssl'
); );
$transport->setUsername($settings['mail_username']); $transport->setUsername($settings['mail_username']);

View File

@@ -99,8 +99,8 @@ class PanelSettings extends AbstractPageSettings
->required(), ->required(),
FileUpload::make('panel_logo_light_'.$this->getPanelID()) FileUpload::make('panel_logo_light_'.$this->getPanelID())
->label('Panel Logo') ->label('Panel Logo')
->visible(fn($get) => $get('panel_show_logo_'.$this->getPanelID()) === 'show') ->visible(fn($get): bool => $get('panel_show_logo_'.$this->getPanelID()) === 'show')
->required(fn($get) => $get('panel_show_logo_'.$this->getPanelID()) === 'show') ->required(fn($get): bool => $get('panel_show_logo_'.$this->getPanelID()) === 'show')
->image() ->image()
->disk('public') ->disk('public')
->visibility('public') ->visibility('public')
@@ -110,8 +110,8 @@ class PanelSettings extends AbstractPageSettings
FileUpload::make('panel_logo_dark_'.$this->getPanelID()) FileUpload::make('panel_logo_dark_'.$this->getPanelID())
->label('Panel Dark Mode Logo') ->label('Panel Dark Mode Logo')
->visible(fn($get) => $get('panel_show_logo_'.$this->getPanelID()) === 'show') ->visible(fn($get): bool => $get('panel_show_logo_'.$this->getPanelID()) === 'show')
->required(fn($get) => $get('panel_show_logo_'.$this->getPanelID()) === 'show') ->required(fn($get): bool => $get('panel_show_logo_'.$this->getPanelID()) === 'show')
->image() ->image()
->disk('public') ->disk('public')
->visibility('public') ->visibility('public')
@@ -123,8 +123,8 @@ class PanelSettings extends AbstractPageSettings
->label('Panel Logo Height') ->label('Panel Logo Height')
->helperText('Use value like `30px`, `2rem`, `20%`, etc. This value applies as style attribute - height: 30px;') ->helperText('Use value like `30px`, `2rem`, `20%`, etc. This value applies as style attribute - height: 30px;')
->columnSpanFull() ->columnSpanFull()
->visible(fn($get) => $get('panel_show_logo_'.$this->getPanelID()) === 'show') ->visible(fn($get): bool => $get('panel_show_logo_'.$this->getPanelID()) === 'show')
->required(fn($get) => $get('panel_show_logo_'.$this->getPanelID()) === 'show'), ->required(fn($get): bool => $get('panel_show_logo_'.$this->getPanelID()) === 'show'),
FileUpload::make('panel_favicon_'.$this->getPanelID()) FileUpload::make('panel_favicon_'.$this->getPanelID())
->label('Panel Favicon') ->label('Panel Favicon')
@@ -172,7 +172,7 @@ class PanelSettings extends AbstractPageSettings
->rgb() ->rgb()
->regex('/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/') ->regex('/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/')
->live() ->live()
->afterStateUpdated(function ($state, callable $set) { ->afterStateUpdated(function ($state, callable $set): void {
$shades = ColorHelper::generateOklchFromRGBShades($state); $shades = ColorHelper::generateOklchFromRGBShades($state);
$set('panel_color_shade_' . $this->getPanelID(), $shades ?? '// Invalid RGB'); $set('panel_color_shade_' . $this->getPanelID(), $shades ?? '// Invalid RGB');
}) })
@@ -191,9 +191,7 @@ class PanelSettings extends AbstractPageSettings
Toggle::make('panel_default') Toggle::make('panel_default')
->label('Is this default panel?') ->label('Is this default panel?')
->helperText('Toggle `ON` to set this panel as default') ->helperText('Toggle `ON` to set this panel as default')
->dehydrateStateUsing(function (bool $state, $get) { ->dehydrateStateUsing(fn(bool $state, $get) => $state ? $get('panel_id') : null)
return $state ? $get('panel_id') : null;
})
])->columns(2), ])->columns(2),
@@ -238,38 +236,38 @@ class PanelSettings extends AbstractPageSettings
TextInput::make('panel_mfa_app_brand_name_'.$this->getPanelID()) TextInput::make('panel_mfa_app_brand_name_'.$this->getPanelID())
->label('MFA Authenticator Brand Name') ->label('MFA Authenticator Brand Name')
->helperText('Optional: Leave to use app name as authenticator brand name') ->helperText('Optional: Leave to use app name as authenticator brand name')
->visible(fn($get) => $get('panel_enable_mfa_'.$this->getPanelID()) && $get('panel_mfa_type_'.$this->getPanelID()) === 'app'), ->visible(fn($get): bool => $get('panel_enable_mfa_'.$this->getPanelID()) && $get('panel_mfa_type_'.$this->getPanelID()) === 'app'),
Toggle::make('panel_mfa_app_recoverable_'.$this->getPanelID()) Toggle::make('panel_mfa_app_recoverable_'.$this->getPanelID())
->label('MFA Authenticator Recoverable') ->label('MFA Authenticator Recoverable')
->live() ->live()
->visible(fn($get) => $get('panel_enable_mfa_'.$this->getPanelID()) && $get('panel_mfa_type_'.$this->getPanelID()) === 'app'), ->visible(fn($get): bool => $get('panel_enable_mfa_'.$this->getPanelID()) && $get('panel_mfa_type_'.$this->getPanelID()) === 'app'),
Toggle::make('panel_mfa_app_recovery_code_regeneratable_'.$this->getPanelID()) Toggle::make('panel_mfa_app_recovery_code_regeneratable_'.$this->getPanelID())
->label('Allow to regenerate recovery code') ->label('Allow to regenerate recovery code')
->live() ->live()
->visible(fn($get) => $get('panel_enable_mfa_'.$this->getPanelID()) && $get('panel_mfa_app_recoverable_'.$this->getPanelID()) && $get('panel_mfa_type_'.$this->getPanelID()) === 'app'), ->visible(fn($get): bool => $get('panel_enable_mfa_'.$this->getPanelID()) && $get('panel_mfa_app_recoverable_'.$this->getPanelID()) && $get('panel_mfa_type_'.$this->getPanelID()) === 'app'),
TextInput::make('panel_mfa_app_recovery_code_count_'.$this->getPanelID()) TextInput::make('panel_mfa_app_recovery_code_count_'.$this->getPanelID())
->label('MFA Authenticator Recovery Code Count') ->label('MFA Authenticator Recovery Code Count')
->numeric() ->numeric()
->minValue(8) ->minValue(8)
->maxValue(16) ->maxValue(16)
->visible(fn($get) => $get('panel_enable_mfa_'.$this->getPanelID()) && $get('panel_mfa_app_recoverable_'.$this->getPanelID()) && $get('panel_mfa_type_'.$this->getPanelID()) === 'app'), ->visible(fn($get): bool => $get('panel_enable_mfa_'.$this->getPanelID()) && $get('panel_mfa_app_recoverable_'.$this->getPanelID()) && $get('panel_mfa_type_'.$this->getPanelID()) === 'app'),
TextInput::make('panel_mfa_app_code_window_'.$this->getPanelID()) TextInput::make('panel_mfa_app_code_window_'.$this->getPanelID())
->label('MFA Authenticator Code Window') ->label('MFA Authenticator Code Window')
->numeric() ->numeric()
->minValue(1) ->minValue(1)
->maxValue(8) ->maxValue(8)
->visible(fn($get) => $get('panel_enable_mfa_'.$this->getPanelID()) && $get('panel_mfa_type_'.$this->getPanelID()) === 'app'), ->visible(fn($get): bool => $get('panel_enable_mfa_'.$this->getPanelID()) && $get('panel_mfa_type_'.$this->getPanelID()) === 'app'),
TextInput::make('panel_mfa_email_code_expiry_'.$this->getPanelID()) TextInput::make('panel_mfa_email_code_expiry_'.$this->getPanelID())
->label('MFA Email Expiry (in minutes)') ->label('MFA Email Expiry (in minutes)')
->numeric() ->numeric()
->minValue(1) ->minValue(1)
->maxValue(8) ->maxValue(8)
->visible(fn($get) => $get('panel_enable_mfa_'.$this->getPanelID()) && $get('panel_mfa_type_'.$this->getPanelID()) === 'email'), ->visible(fn($get): bool => $get('panel_enable_mfa_'.$this->getPanelID()) && $get('panel_mfa_type_'.$this->getPanelID()) === 'email'),
Select::make('panel_mfa_is_required_'.$this->getPanelID()) Select::make('panel_mfa_is_required_'.$this->getPanelID())
->label('MFA Is Required') ->label('MFA Is Required')

View File

@@ -10,17 +10,17 @@ class ColorHelper
/** /**
* Convert RGB to OKLab color space. * Convert RGB to OKLab color space.
*/ */
public static function rgbToOklab($r, $g, $b) public static function rgbToOklab($r, $g, $b): array
{ {
// Normalize RGB values to the range [0, 1] // Normalize RGB values to the range [0, 1]
$r = $r / 255; $r /= 255;
$g = $g / 255; $g /= 255;
$b = $b / 255; $b /= 255;
// Linearize RGB values // Linearize RGB values
$r = $r <= 0.04045 ? $r / 12.92 : pow(($r + 0.055) / 1.055, 2.4); $r = $r <= 0.04045 ? $r / 12.92 : (($r + 0.055) / 1.055) ** 2.4;
$g = $g <= 0.04045 ? $g / 12.92 : pow(($g + 0.055) / 1.055, 2.4); $g = $g <= 0.04045 ? $g / 12.92 : (($g + 0.055) / 1.055) ** 2.4;
$b = $b <= 0.04045 ? $b / 12.92 : pow(($b + 0.055) / 1.055, 2.4); $b = $b <= 0.04045 ? $b / 12.92 : (($b + 0.055) / 1.055) ** 2.4;
// Convert to linear light values // Convert to linear light values
$l = 0.4122214708 * $r + 0.5363325363 * $g + 0.0514459929 * $b; $l = 0.4122214708 * $r + 0.5363325363 * $g + 0.0514459929 * $b;
@@ -28,9 +28,9 @@ class ColorHelper
$s = 0.0883024619 * $r + 0.2817188376 * $g + 0.6299787005 * $b; $s = 0.0883024619 * $r + 0.2817188376 * $g + 0.6299787005 * $b;
// Apply the OKLab transformation // Apply the OKLab transformation
$l_ = pow($l, 1 / 3); $l_ = $l ** (1 / 3);
$m_ = pow($m, 1 / 3); $m_ = $m ** (1 / 3);
$s_ = pow($s, 1 / 3); $s_ = $s ** (1 / 3);
$L = 0.2104542553 * $l_ + 0.7936177850 * $m_ - 0.0040720468 * $s_; $L = 0.2104542553 * $l_ + 0.7936177850 * $m_ - 0.0040720468 * $s_;
$a = 1.9779984951 * $l_ - 2.4285922050 * $m_ + 0.4505937099 * $s_; $a = 1.9779984951 * $l_ - 2.4285922050 * $m_ + 0.4505937099 * $s_;
@@ -42,7 +42,7 @@ class ColorHelper
/** /**
* Convert OKLab to OKLCH color space. * Convert OKLab to OKLCH color space.
*/ */
public static function oklabToOklch($L, $a, $b) public static function oklabToOklch($L, $a, $b): array
{ {
$C = sqrt($a * $a + $b * $b); // Chroma $C = sqrt($a * $a + $b * $b); // Chroma
$h = atan2($b, $a); // Hue in radians $h = atan2($b, $a); // Hue in radians
@@ -88,7 +88,7 @@ class ColorHelper
*/ */
public static function generateOklchFromRGBShades(string $rgbString): ?string public static function generateOklchFromRGBShades(string $rgbString): ?string
{ {
if (!preg_match('/rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)/', $rgbString, $matches)) { if (in_array(preg_match('/rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)/', $rgbString, $matches), [0, false], true)) {
return null; return null;
} }
@@ -136,13 +136,13 @@ class ColorHelper
{ {
try { try {
$panelColor = []; $panelColor = [];
if ($panelId != "") { if ($panelId !== "") {
$colors = db_config('panel.panel_color_'.$panelId) ?? []; $colors = db_config('panel.panel_color_'.$panelId) ?? [];
$isRGB = db_config('panel.panel_color_isRGB_'.$panelId) ?? false; $isRGB = db_config('panel.panel_color_isRGB_'.$panelId) ?? false;
foreach ($colors as $color) { foreach ($colors as $color) {
$colorName = $color['panel_color_name_'.$panelId]; $colorName = $color['panel_color_name_'.$panelId];
$colorRGB = $color['panel_color_'.$panelId]; $colorRGB = $color['panel_color_'.$panelId];
$colorOKLCH = json_decode($color['panel_color_shade_'.$panelId], true); $colorOKLCH = json_decode((string) $color['panel_color_shade_'.$panelId], true);
$panelColor[$colorName] = $isRGB ? $colorRGB : $colorOKLCH; $panelColor[$colorName] = $isRGB ? $colorRGB : $colorOKLCH;
} }
} }

View File

@@ -14,11 +14,11 @@ class DynamicMailConfigServiceProvider extends ServiceProvider
// Mail configuration properties // Mail configuration properties
private string $mailDriver; private string $mailDriver;
private ?string $mailScheme; private ?string $mailScheme = null;
private string $mailHost; private string $mailHost;
private string $mailPort; private string $mailPort;
private ?string $mailUsername; private ?string $mailUsername = null;
private ?string $mailPassword; private ?string $mailPassword = null;
private string $mailFromAddress; private string $mailFromAddress;
private string $mailFromName; private string $mailFromName;
private int $mailTimeout; private int $mailTimeout;
@@ -65,9 +65,10 @@ class DynamicMailConfigServiceProvider extends ServiceProvider
private function loadConfiguration(): void private function loadConfiguration(): void
{ {
try { try {
$this->mailConfig = DbConfig::getGroup('mail') ?: []; $group = DbConfig::getGroup('mail');
$this->mailConfig = (in_array($group, [null, []], true)) ? [] : $group;
$this->mailConfig['app_url'] = db_config('website.site_url') ?? env('APP_URL', 'http://localhost'); $this->mailConfig['app_url'] = db_config('website.site_url') ?? env('APP_URL', 'http://localhost');
} catch (\Throwable $e) { } catch (\Throwable) {
Log::warning('Database mail configuration unavailable; falling back to env values.'); Log::warning('Database mail configuration unavailable; falling back to env values.');
$this->mailConfig = ['app_url' => env('APP_URL', 'http://localhost')]; $this->mailConfig = ['app_url' => env('APP_URL', 'http://localhost')];
} }
@@ -83,7 +84,7 @@ class DynamicMailConfigServiceProvider extends ServiceProvider
$this->mailFromName = $this->getConfig('mail_from_name', env('MAIL_FROM_NAME', 'Example')); $this->mailFromName = $this->getConfig('mail_from_name', env('MAIL_FROM_NAME', 'Example'));
$this->mailFromAddress = $this->getConfig('mail_from_address', env('MAIL_FROM_ADDRESS', 'hello@example.com')); $this->mailFromAddress = $this->getConfig('mail_from_address', env('MAIL_FROM_ADDRESS', 'hello@example.com'));
$this->mailTimeout = $this->getConfig('mail_timeout', env('MAIL_TIMEOUT', 15)); $this->mailTimeout = $this->getConfig('mail_timeout', env('MAIL_TIMEOUT', 15));
$this->mailEHLO = $this->getConfig('mail_ehlo', env('MAIL_EHLO', parse_url((string) $this->appUrl, PHP_URL_HOST))); $this->mailEHLO = $this->getConfig('mail_ehlo', env('MAIL_EHLO', parse_url($this->appUrl, PHP_URL_HOST)));
} }
private function getConfig(string $key, $default = null) private function getConfig(string $key, $default = null)

View File

@@ -49,7 +49,7 @@ class DashPanelProvider extends PanelProvider
private bool $panelBrandLogoShow; private bool $panelBrandLogoShow;
private string $panelBrandLogoLight; private string $panelBrandLogoLight;
private string $panelBrandLogoDark; private string $panelBrandLogoDark;
private ?string $panelBrandLogoHeight; private ?string $panelBrandLogoHeight = null;
private string $panelFavicon; private string $panelFavicon;
// MFA configuration properties // MFA configuration properties
@@ -108,7 +108,10 @@ class DashPanelProvider extends PanelProvider
FilamentLogViewerPlugin::make(), FilamentLogViewerPlugin::make(),
FilamentMailsPlugin::make()->canManageMails(function (): bool { FilamentMailsPlugin::make()->canManageMails(function (): bool {
$user = Auth::user(); $user = Auth::user();
return $user->hasRole('admin') || $user->hasPermissionTo('manage mails'); if ($user->hasRole('admin')) {
return true;
}
return (bool) $user->hasPermissionTo('manage mails');
}), }),
]) ])
->routes(fn() => FilamentMails::routes()); ->routes(fn() => FilamentMails::routes());
@@ -121,10 +124,10 @@ class DashPanelProvider extends PanelProvider
private function loadConfiguration(): void private function loadConfiguration(): void
{ {
try { try {
$this->panelConfig = DbConfig::getGroup('panel'); $group = DbConfig::getGroup('panel');
$this->panelConfig = (in_array($group, [null, []], true)) ? [] : $group;
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error($e->getMessage()); Log::error($e->getMessage());
$this->panelConfig = [];
} }
// Load basic panel configuration // Load basic panel configuration
@@ -166,14 +169,14 @@ class DashPanelProvider extends PanelProvider
private function applyConditionalConfiguration(Panel $panel): void private function applyConditionalConfiguration(Panel $panel): void
{ {
$actions = [ $actions = [
'login' => [$this->panelLogin, fn() => $panel->login()], 'login' => [$this->panelLogin, fn(): \Filament\Panel => $panel->login()],
'register' => [$this->panelRegistration, fn() => $panel->registration()], 'register' => [$this->panelRegistration, fn(): \Filament\Panel => $panel->registration()],
'profile' => [$this->panelProfile, fn() => $panel->profile()], 'profile' => [$this->panelProfile, fn(): \Filament\Panel => $panel->profile()],
'spa' => [$this->panelSPA, fn() => $panel 'spa' => [$this->panelSPA, fn(): \Filament\Panel => $panel
->spa(hasPrefetching: $this->panelSPAPrefetch) ->spa(hasPrefetching: $this->panelSPAPrefetch)
->spaUrlExceptions(exceptions: $this->panelSPAExceptions) ->spaUrlExceptions(exceptions: $this->panelSPAExceptions)
], ],
'logo' => [$this->panelBrandLogoShow, fn() => $panel 'logo' => [$this->panelBrandLogoShow, fn(): \Filament\Panel => $panel
->brandLogo(asset($this->panelBrandLogoLight)) ->brandLogo(asset($this->panelBrandLogoLight))
->darkModeBrandLogo(asset($this->panelBrandLogoDark)) ->darkModeBrandLogo(asset($this->panelBrandLogoDark))
->brandLogoHeight($this->panelBrandLogoHeight) ->brandLogoHeight($this->panelBrandLogoHeight)
@@ -181,7 +184,9 @@ class DashPanelProvider extends PanelProvider
]; ];
foreach ($actions as [$condition, $callback]) { foreach ($actions as [$condition, $callback]) {
$condition && $callback(); if ($condition) {
$callback();
}
} }
$this->configureMFA($panel); $this->configureMFA($panel);