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

View File

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

View File

@@ -10,17 +10,17 @@ class ColorHelper
/**
* 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]
$r = $r / 255;
$g = $g / 255;
$b = $b / 255;
$r /= 255;
$g /= 255;
$b /= 255;
// Linearize RGB values
$r = $r <= 0.04045 ? $r / 12.92 : pow(($r + 0.055) / 1.055, 2.4);
$g = $g <= 0.04045 ? $g / 12.92 : pow(($g + 0.055) / 1.055, 2.4);
$b = $b <= 0.04045 ? $b / 12.92 : pow(($b + 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 : (($g + 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
$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;
// Apply the OKLab transformation
$l_ = pow($l, 1 / 3);
$m_ = pow($m, 1 / 3);
$s_ = pow($s, 1 / 3);
$l_ = $l ** (1 / 3);
$m_ = $m ** (1 / 3);
$s_ = $s ** (1 / 3);
$L = 0.2104542553 * $l_ + 0.7936177850 * $m_ - 0.0040720468 * $s_;
$a = 1.9779984951 * $l_ - 2.4285922050 * $m_ + 0.4505937099 * $s_;
@@ -42,7 +42,7 @@ class ColorHelper
/**
* 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
$h = atan2($b, $a); // Hue in radians
@@ -88,7 +88,7 @@ class ColorHelper
*/
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;
}
@@ -136,13 +136,13 @@ class ColorHelper
{
try {
$panelColor = [];
if ($panelId != "") {
if ($panelId !== "") {
$colors = db_config('panel.panel_color_'.$panelId) ?? [];
$isRGB = db_config('panel.panel_color_isRGB_'.$panelId) ?? false;
foreach ($colors as $color) {
$colorName = $color['panel_color_name_'.$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;
}
}

View File

@@ -14,11 +14,11 @@ class DynamicMailConfigServiceProvider extends ServiceProvider
// Mail configuration properties
private string $mailDriver;
private ?string $mailScheme;
private ?string $mailScheme = null;
private string $mailHost;
private string $mailPort;
private ?string $mailUsername;
private ?string $mailPassword;
private ?string $mailUsername = null;
private ?string $mailPassword = null;
private string $mailFromAddress;
private string $mailFromName;
private int $mailTimeout;
@@ -65,9 +65,10 @@ class DynamicMailConfigServiceProvider extends ServiceProvider
private function loadConfiguration(): void
{
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');
} catch (\Throwable $e) {
} catch (\Throwable) {
Log::warning('Database mail configuration unavailable; falling back to env values.');
$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->mailFromAddress = $this->getConfig('mail_from_address', env('MAIL_FROM_ADDRESS', 'hello@example.com'));
$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)

View File

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