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,13 @@
namespace App\Filament\Widgets;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\DB;
use App\Models\Log;
use App\Models\Meta;
use App\Models\PremiumEmail;
use App\Models\Ticket;
use App\Models\User;
use Carbon\Carbon;
use DB;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
@@ -26,39 +26,39 @@ class StatsOverview extends BaseWidget
->descriptionIcon($this->getComparisonIcon($this->getCustomerCount(), $this->getCustomerCount('yesterday')))
->color($this->getComparisonColor($this->getCustomerCount(), $this->getCustomerCount('yesterday'))),
Stat::make('Paid Users', $this->getUserPaid())
->description($this->getComparisonDescription($this->getUserPaid(), $this->getUserPaid('yesterday')))
->descriptionIcon($this->getComparisonIcon($this->getUserPaid(), $this->getUserPaid('yesterday')))
->color($this->getComparisonColor($this->getUserPaid(), $this->getUserPaid('yesterday'))),
->description($this->getComparisonDescription($this->getUserPaid(), $this->getUserPaid()))
->descriptionIcon($this->getComparisonIcon($this->getUserPaid(), $this->getUserPaid()))
->color($this->getComparisonColor($this->getUserPaid(), $this->getUserPaid())),
Stat::make('Logs Count', $this->getLogsCount())
->description($this->getComparisonDescription($this->getLogsCount(), $this->getLogsCount('yesterday')))
->descriptionIcon($this->getComparisonIcon($this->getLogsCount(), $this->getLogsCount('yesterday')))
->color($this->getComparisonColor($this->getLogsCount(), $this->getLogsCount('yesterday'))),
Stat::make('Total Mailbox', $this->getTotalMailbox())
->description($this->getComparisonDescription($this->getTotalMailbox(), $this->getTotalMailbox('yesterday')))
->descriptionIcon($this->getComparisonIcon($this->getTotalMailbox(), $this->getTotalMailbox('yesterday')))
->color($this->getComparisonColor($this->getTotalMailbox(), $this->getTotalMailbox('yesterday'))),
->description($this->getComparisonDescription($this->getTotalMailbox(), $this->getTotalMailbox()))
->descriptionIcon($this->getComparisonIcon($this->getTotalMailbox(), $this->getTotalMailbox()))
->color($this->getComparisonColor($this->getTotalMailbox(), $this->getTotalMailbox())),
Stat::make('Emails Received', $this->getTotalEmailsReceived())
->description($this->getComparisonDescription($this->getTotalEmailsReceived(), $this->getTotalEmailsReceived('yesterday')))
->descriptionIcon($this->getComparisonIcon($this->getTotalEmailsReceived(), $this->getTotalEmailsReceived('yesterday')))
->color($this->getComparisonColor($this->getTotalEmailsReceived(), $this->getTotalEmailsReceived('yesterday'))),
->description($this->getComparisonDescription($this->getTotalEmailsReceived(), $this->getTotalEmailsReceived()))
->descriptionIcon($this->getComparisonIcon($this->getTotalEmailsReceived(), $this->getTotalEmailsReceived()))
->color($this->getComparisonColor($this->getTotalEmailsReceived(), $this->getTotalEmailsReceived())),
Stat::make('Emails Stored', $this->getStoreEmailsCount())
->description($this->getComparisonDescription($this->getStoreEmailsCount(), $this->getStoreEmailsCount('yesterday')))
->descriptionIcon($this->getComparisonIcon($this->getStoreEmailsCount(), $this->getStoreEmailsCount('yesterday')))
->color($this->getComparisonColor($this->getStoreEmailsCount(), $this->getStoreEmailsCount('yesterday'))),
Stat::make('Open Tickets', $this->getOpenTicketsCount())
->description($this->getComparisonDescription($this->getOpenTicketsCount(), $this->getOpenTicketsCount('yesterday')))
->descriptionIcon($this->getComparisonIcon($this->getOpenTicketsCount(), $this->getOpenTicketsCount('yesterday')))
->color($this->getComparisonColor($this->getOpenTicketsCount(), $this->getOpenTicketsCount('yesterday'))),
->description($this->getComparisonDescription($this->getOpenTicketsCount(), $this->getOpenTicketsCount()))
->descriptionIcon($this->getComparisonIcon($this->getOpenTicketsCount(), $this->getOpenTicketsCount()))
->color($this->getComparisonColor($this->getOpenTicketsCount(), $this->getOpenTicketsCount())),
Stat::make('Closed Tickets', $this->getClosedTicketsCount())
->description($this->getComparisonDescription($this->getClosedTicketsCount(), $this->getClosedTicketsCount('yesterday')))
->descriptionIcon($this->getComparisonIcon($this->getClosedTicketsCount(), $this->getClosedTicketsCount('yesterday')))
->color($this->getComparisonColor($this->getClosedTicketsCount(), $this->getClosedTicketsCount('yesterday'))),
->description($this->getComparisonDescription($this->getClosedTicketsCount(), $this->getClosedTicketsCount()))
->descriptionIcon($this->getComparisonIcon($this->getClosedTicketsCount(), $this->getClosedTicketsCount()))
->color($this->getComparisonColor($this->getClosedTicketsCount(), $this->getClosedTicketsCount())),
];
}
private function getComparisonDescription(int $today, int $yesterday): string
{
if ($today == $yesterday) {
if ($today === $yesterday) {
return 'No change';
}
@@ -76,7 +76,7 @@ class StatsOverview extends BaseWidget
private function getComparisonIcon(int $today, int $yesterday): ?string
{
if ($today == $yesterday) {
if ($today === $yesterday) {
return null;
}
@@ -85,7 +85,7 @@ class StatsOverview extends BaseWidget
private function getComparisonColor(int $today, int $yesterday): string
{
if ($today == $yesterday) {
if ($today === $yesterday) {
return 'gray';
}
@@ -95,13 +95,13 @@ class StatsOverview extends BaseWidget
private function getUser(string $period = 'today'): int
{
if ($period === 'yesterday') {
return User::where('created_at', '<', Carbon::today('UTC')->startOfDay())->count();
return User::query()->where('created_at', '<', Date::today('UTC')->startOfDay())->count();
}
return User::count();
return User::query()->count();
}
private function getUserPaid(string $period = 'today'): int
private function getUserPaid(): int
{
return DB::table('subscriptions')
->where('stripe_status', 'active')
@@ -112,49 +112,49 @@ class StatsOverview extends BaseWidget
private function getLogsCount(string $period = 'today'): int
{
if ($period === 'yesterday') {
return Log::where('created_at', '<', Carbon::today('UTC')->startOfDay())->count();
return Log::query()->where('created_at', '<', Date::today('UTC')->startOfDay())->count();
}
return Log::count();
return Log::query()->count();
}
private function getTotalMailbox(string $period = 'today'): int
private function getTotalMailbox(): int
{
return Meta::select('value')->where('key', 'email_ids_created')->first()->value ?? 0;
return Meta::query()->select('value')->where('key', 'email_ids_created')->first()->value ?? 0;
}
private function getTotalEmailsReceived(string $period = 'today'): int
private function getTotalEmailsReceived(): int
{
return Meta::select('value')->where('key', 'messages_received')->first()->value ?? 0;
return Meta::query()->select('value')->where('key', 'messages_received')->first()->value ?? 0;
}
private function getCustomerCount(string $period = 'today'): int
{
if ($period === 'yesterday') {
return User::whereNotNull('stripe_id')
->where('created_at', '<', Carbon::today('UTC')->startOfDay())
return User::query()->whereNotNull('stripe_id')
->where('created_at', '<', Date::today('UTC')->startOfDay())
->count();
}
return User::whereNotNull('stripe_id')->count();
return User::query()->whereNotNull('stripe_id')->count();
}
private function getStoreEmailsCount(string $period = 'today'): int
{
if ($period === 'yesterday') {
return PremiumEmail::where('created_at', '<', Carbon::today('UTC')->startOfDay())->count();
return PremiumEmail::query()->where('created_at', '<', Date::today('UTC')->startOfDay())->count();
}
return PremiumEmail::count();
return PremiumEmail::query()->count();
}
private function getOpenTicketsCount(string $period = 'today'): int
private function getOpenTicketsCount(): int
{
return Ticket::whereIn('status', ['open', 'pending'])->count();
return Ticket::query()->whereIn('status', ['open', 'pending'])->count();
}
private function getClosedTicketsCount(string $period = 'today'): int
private function getClosedTicketsCount(): int
{
return Ticket::whereIn('status', ['closed'])->count();
return Ticket::query()->whereIn('status', ['closed'])->count();
}
}