Skip to content

Commit

Permalink
[Fix] PHPStan issues (#6)
Browse files Browse the repository at this point in the history
* Use type hints

* Remove deprecated setting

* Fix styling

* Fix remaining issues

* Fix styling

* Fix styling

* wip

---------

Co-authored-by: Baspa <[email protected]>
  • Loading branch information
Baspa and Baspa authored Dec 27, 2024
1 parent d78ad3d commit ab13d2b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 30 deletions.
2 changes: 0 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ parameters:
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
checkMissingIterableValueType: false

41 changes: 30 additions & 11 deletions src/Resources/MailResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Vormkracht10\FilamentMails\Resources;

use Filament\Facades\Filament;
use Filament\Forms\Components\TagsInput;
use Filament\Infolists\Components\Grid;
use Filament\Infolists\Components\RepeatableEntry;
Expand Down Expand Up @@ -174,10 +175,19 @@ public static function infolist(Infolist $infolist): Infolist
TextEntry::make('type')
->label(__('Type'))
->badge()
->url(fn (MailEvent $record) => route('filament.' . filament()->getCurrentPanel()?->getId() . '.resources.mails.events.view', [
'record' => $record,
'tenant' => filament()->getTenant()?->id,
]))
->url(function (Mail $record) {
$panel = Filament::getCurrentPanel();
$tenant = Filament::getTenant();

if (! $panel || ! $tenant) {
return null;
}

return route('filament.' . $panel->getId() . '.resources.mails.events.view', [
'record' => $record,
'tenant' => $tenant->getKey(),
]);
})
->color(fn (EventType $state): string => match ($state) {
EventType::DELIVERED => 'success',
EventType::CLICKED => 'clicked',
Expand All @@ -192,10 +202,19 @@ public static function infolist(Infolist $infolist): Infolist
return ucfirst($state->value);
}),
TextEntry::make('occurred_at')
->url(fn (MailEvent $record) => route('filament.' . filament()->getCurrentPanel()?->getId() . '.resources.mails.events.view', [
'record' => $record,
'tenant' => filament()->getTenant()?->id,
]))
->url(function (MailEvent $record) {
$panel = Filament::getCurrentPanel();
$tenant = Filament::getTenant();

if (! $panel || ! $tenant) {
return null;
}

return route('filament.' . $panel->getId() . '.resources.mails.events.view', [
'record' => $record,
'tenant' => $tenant->getKey(),
]);
})
->since()
->dateTimeTooltip('d-m-Y H:i')
->label(__('Occurred At')),
Expand Down Expand Up @@ -366,8 +385,8 @@ public static function table(Table $table): Table
->fillForm(function (Mail $record) {
return [
'to' => array_keys($record->to),
'cc' => is_array($record->cc) ? array_keys($record->cc) : null,
'bcc' => is_array($record->bcc) ? array_keys($record->bcc) : null,
'cc' => array_keys($record->cc),
'bcc' => array_keys($record->bcc),
];
})
->action(function (Mail $record, array $data) {
Expand Down Expand Up @@ -430,7 +449,7 @@ private static function formatMailState(array $emails, bool $mailOnly = false):
{
return collect($emails)
->mapWithKeys(fn ($value, $key) => [$key => $value ?? $key])
->map(fn ($value, $key) => $mailOnly ? $key : ($value === null ? $key : "$value <$key>"))
->map(fn ($value, $key) => $mailOnly ? $key : ($value == null ? $key : "$value <$key>"))
->implode(', ');
}

Expand Down
33 changes: 24 additions & 9 deletions src/Resources/MailResource/Pages/ListMails.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Database\Eloquent\Builder;
use Vormkracht10\FilamentMails\Resources\MailResource;
use Vormkracht10\FilamentMails\Resources\MailResource\Widgets\MailStatsWidget;
use Vormkracht10\Mails\Models\Mail;

class ListMails extends ListRecords
{
Expand All @@ -24,8 +25,11 @@ protected function getActions(): array

public function getTabs(): array
{
/** @var Mail $class */
$class = config('mails.models.mail');

$class = new $class;

return [
'all' => Tab::make()
->label(__('All'))
Expand All @@ -38,46 +42,57 @@ public function getTabs(): array
->badgeColor('info')
->icon('heroicon-o-paper-airplane')
->badge($class::sent()->count())
->modifyQueryUsing(fn (Builder $query) => $query->sent()),
->modifyQueryUsing(function (Builder $query) use ($class): Builder {
return $class->sent();
}),

'delivered' => Tab::make()
->label(__('Delivered'))
->badgeColor('success')
->icon('heroicon-o-check-circle')
->badge($class::delivered()->count())
->modifyQueryUsing(fn (Builder $query) => $query->delivered()),
->modifyQueryUsing(function (Builder $query) use ($class): Builder {
return $class->delivered();
}),

'opened' => Tab::make()
->label(__('Opened'))
->badgeColor('info')
->icon('heroicon-o-eye')
->badge($class::opened()->count())
->modifyQueryUsing(fn (Builder $query) => $query->opened()),
->modifyQueryUsing(function (Builder $query) use ($class): Builder {
return $class->opened();
}),

'clicked' => Tab::make()
->label(__('Clicked'))
->badgeColor('clicked')
->icon('heroicon-o-cursor-arrow-rays')
->badge($class::clicked()->count())
->modifyQueryUsing(fn (Builder $query) => $query->clicked()),
->modifyQueryUsing(function (Builder $query) use ($class): Builder {
return $class->clicked();
}),

'bounced' => Tab::make()
->label(__('Bounced'))
->badgeColor('danger')
->icon('heroicon-o-x-circle')
->badge(fn () => $class::softBounced()->count() + $class::hardBounced()->count())
->modifyQueryUsing(fn (Builder $query) => $query->where(function ($query) {
$query->softBounced()->orWhere(function ($query) {
$query->hardBounced();
->modifyQueryUsing(function (Builder $query) use ($class): Builder {
return $query->where(function (Builder $subQuery) use ($class) {
return $subQuery->whereIn('id', $class::softBounced()->select('id'))
->orWhereIn('id', $class::hardBounced()->select('id'));
});
})),
}),

'unsent' => Tab::make()
->label(__('Unsent'))
->badgeColor('gray')
->icon('heroicon-o-x-circle')
->badge($class::unsent()->count())
->modifyQueryUsing(fn (Builder $query) => $query->unsent()),
->modifyQueryUsing(function (Builder $query) use ($class): Builder {
return $class->unsent();
}),
];
}

Expand Down
25 changes: 17 additions & 8 deletions src/Resources/MailResource/Widgets/MailStatsWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Vormkracht10\FilamentMails\Resources\MailResource\Widgets;

use Filament\Facades\Filament;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;

Expand All @@ -26,6 +27,20 @@ protected function getStats(): array
return [];
}

$generateUrl = function (string $activeTab): ?string {
$panel = Filament::getCurrentPanel();
$tenant = Filament::getTenant();

if (! $panel || ! $tenant) {
return null;
}

return route('filament.' . $panel->getId() . '.resources.mails.index', [
'activeTab' => $activeTab,
'tenant' => $tenant->getKey(),
]);
};

$widgets[] = Stat::make(__('Delivered'), number_format(($deliveredMails / $mailCount) * 100, 1) . '%')
->label(__('Delivered'))
->description($deliveredMails . ' ' . __('of') . ' ' . $mailCount . ' ' . __('emails'))
Expand All @@ -35,10 +50,7 @@ protected function getStats(): array
->label(__('Opened'))
->description($openedMails . ' ' . __('of') . ' ' . $mailCount . ' ' . __('emails'))
->color('info')
->url(route('filament.' . filament()->getCurrentPanel()?->getId() . '.resources.mails.index', [
'activeTab' => 'opened',
'tenant' => filament()->getTenant()?->id,
]));
->url($generateUrl('opened'));

$widgets[] = Stat::make(__('Clicked'), number_format(($clickedMails / $mailCount) * 100, 1) . '%')
->label(__('Clicked'))
Expand All @@ -49,10 +61,7 @@ protected function getStats(): array
->label(__('Bounced'))
->description($bouncedMails . ' ' . __('of') . ' ' . $mailCount . ' ' . __('emails'))
->color('danger')
->url(route('filament.' . filament()->getCurrentPanel()?->getId() . '.resources.mails.index', [
'activeTab' => 'bounced',
'tenant' => filament()->getTenant()?->id,
]));
->url($generateUrl('bounced'));

return $widgets;
}
Expand Down

0 comments on commit ab13d2b

Please sign in to comment.