Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__.'/src',
__DIR__.'/tests',
]);

$rectorConfig->sets([
Expand Down
4 changes: 2 additions & 2 deletions src/Actions/AttachUuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function handle(MessageSending $messageSending): MessageSending

public function getProvider(MessageSending $messageSending): string
{
return config('mail.mailers.' . $messageSending->data['mailer'] . '.transport') ?? $messageSending->data['mailer'];
return config('mail.mailers.'.$messageSending->data['mailer'].'.transport') ?? $messageSending->data['mailer'];
}

public function shouldTrackMails(string $provider): bool
Expand All @@ -39,7 +39,7 @@ public function shouldTrackMails(string $provider): bool

public function driverExistsForProvider(string $provider): bool
{
return class_exists('Backstage\\Mails\\Drivers\\' . ucfirst($provider) . 'Driver');
return class_exists('Backstage\\Mails\\Drivers\\'.ucfirst($provider).'Driver');
}

public function trackingEnabled(): bool
Expand Down
16 changes: 8 additions & 8 deletions src/Actions/LogMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LogMail
{
use AsAction;

public function handle(MessageSending | MessageSent $event): mixed
public function handle(MessageSending|MessageSent $event): mixed
{
if (! config('mails.logging.enabled')) {
return null;
Expand Down Expand Up @@ -49,14 +49,14 @@ public function newMailModelInstance()
return new $model;
}

public function getOnlyConfiguredAttributes(MessageSending | MessageSent $event): array
public function getOnlyConfiguredAttributes(MessageSending|MessageSent $event): array
{
return collect($this->getDefaultLogAttributes($event))
->only($this->getConfiguredAttributes())
->merge($this->getMandatoryAttributes($event))
->merge([
'mailer' => $event->data['mailer'],
'transport' => config('mail.mailers.' . $event->data['mailer'] . '.transport'),
'transport' => config('mail.mailers.'.$event->data['mailer'].'.transport'),
])
->toArray();
}
Expand All @@ -66,7 +66,7 @@ public function getConfiguredAttributes(): array
return (array) config('mails.logging.attributes');
}

public function getDefaultLogAttributes(MessageSending | MessageSent $event): array
public function getDefaultLogAttributes(MessageSending|MessageSent $event): array
{
return [
'subject' => $event->message->getSubject(),
Expand All @@ -81,7 +81,7 @@ public function getDefaultLogAttributes(MessageSending | MessageSent $event): ar
];
}

protected function getStreamId(MessageSending | MessageSent $event): ?string
protected function getStreamId(MessageSending|MessageSent $event): ?string
{
if ($event->data['mailer'] !== Provider::POSTMARK) {
return null;
Expand All @@ -94,18 +94,18 @@ protected function getStreamId(MessageSending | MessageSent $event): ?string
return config('mail.mailers.postmark.message_stream_id', 'outbound');
}

public function getMandatoryAttributes(MessageSending | MessageSent $event): array
public function getMandatoryAttributes(MessageSending|MessageSent $event): array
{
return [
'uuid' => $this->getCustomUuid($event),
// 'mail_class' => $this->getMailClassHeaderValue($event),
'mail_class' => $event->data['__laravel_mailable'] ?? null,
'sent_at' => $event instanceof MessageSent ? now() : null,
'mailer' => $event->data['mailer'],
'stream_id' => $this->getStreamId($event),
];
}

protected function getCustomUuid(MessageSending | MessageSent $event): ?string
protected function getCustomUuid(MessageSending|MessageSent $event): ?string
{
if (! $event->message->getHeaders()->has(config('mails.headers.uuid'))) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/CheckBounceRateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CheckBounceRateCommand extends Command
{
protected $signature = 'mail:bounce-rate';

protected $description = 'Check if the bounce rate is higher than the configured limit ' .
protected $description = 'Check if the bounce rate is higher than the configured limit '.
'and send a notification if it is.';

public function handle(): int
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ResendMailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function handle(): int
{
$uuid = $this->argument('uuid');

$mail = mail::where('uuid', $uuid)->first();
$mail = Mail::where('uuid', $uuid)->first();

if (is_null($mail)) {
$this->components->error("Mail with uuid: \"{$uuid}\" does not exist");
Expand Down
6 changes: 3 additions & 3 deletions src/Drivers/MailgunDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function verifyWebhookSignature(array $payload): bool
return false;
}

$hmac = hash_hmac('sha256', $payload['signature']['timestamp'] . $payload['signature']['token'], (string) config('services.mailgun.webhook_signing_key'));
$hmac = hash_hmac('sha256', $payload['signature']['timestamp'].$payload['signature']['token'], (string) config('services.mailgun.webhook_signing_key'));

if (function_exists('hash_equals')) {
return hash_equals($hmac, $payload['signature']['signature']);
Expand Down Expand Up @@ -142,8 +142,8 @@ public function unsuppressEmailAddress(string $address, ?int $stream_id = null):
{
$pendingRequest = Http::asJson()
->withBasicAuth('api', config('services.mailgun.secret'))
->baseUrl(config('services.mailgun.endpoint') . '/v3/');
->baseUrl(config('services.mailgun.endpoint').'/v3/');

return $pendingRequest->delete(config('services.mailgun.domain') . '/unsubscribes/' . $address);
return $pendingRequest->delete(config('services.mailgun.domain').'/unsubscribes/'.$address);
}
}
4 changes: 2 additions & 2 deletions src/Drivers/PostmarkDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function verifyWebhookSignature(array $payload): bool

public function attachUuidToMail(MessageSending $messageSending, string $uuid): MessageSending
{
$messageSending->message->getHeaders()->addTextHeader('X-PM-Metadata-' . config('mails.headers.uuid'), $uuid);
$messageSending->message->getHeaders()->addTextHeader('X-PM-Metadata-'.config('mails.headers.uuid'), $uuid);

return $messageSending;
}
Expand Down Expand Up @@ -182,7 +182,7 @@ public function unsuppressEmailAddress(string $address, ?int $stream_id = null):
])
->baseUrl('https://api.postmarkapp.com/');

return $pendingRequest->post('message-streams/' . $stream_id . '/suppressions/delete', [
return $pendingRequest->post('message-streams/'.$stream_id.'/suppressions/delete', [
'Suppressions' => [['emailAddress' => $address]],
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Listeners/StoreMailRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function shouldAssociateModels(Email $email): bool
);
}

protected function getAssociatedModels(Email $email): array | false
protected function getAssociatedModels(Email $email): array|false
{
$encrypted = $this->getHeaderBody(
$email,
Expand Down
2 changes: 1 addition & 1 deletion src/MailsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function configurePackage(Package $package): void
*/
protected function getMigrations(): array
{
return collect(app(Filesystem::class)->files(__DIR__ . '/../database/migrations'))
return collect(app(Filesystem::class)->files(__DIR__.'/../database/migrations'))
->map(fn (SplFileInfo $file): string => str_replace('.php.stub', '', $file->getBasename()))
->toArray();
}
Expand Down
10 changes: 10 additions & 0 deletions src/Models/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ public function scopeUnsent(Builder $builder): Builder
return $builder->whereNull('sent_at');
}

public function scopeForUuid(Builder $builder, string $uuid): Builder
{
return $builder->where('uuid', $uuid);
}

public function scopeForMailClass(Builder $builder, string $mailClass): Builder
{
return $builder->where('mail_class', $mailClass);
}

protected function status(): Attribute
{
return Attribute::make(get: function () {
Expand Down
2 changes: 1 addition & 1 deletion src/Models/MailAttachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function mail(): BelongsTo

protected function storagePath(): Attribute
{
return Attribute::make(get: fn (): string => rtrim((string) config('mails.logging.attachments.root'), '/') . '/' . $this->getKey() . '/' . $this->filename);
return Attribute::make(get: fn (): string => rtrim((string) config('mails.logging.attachments.root'), '/').'/'.$this->getKey().'/'.$this->filename);
}

protected function fileData(): Attribute
Expand Down
2 changes: 1 addition & 1 deletion src/Models/MailEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@ public function scopeSuppressed(Builder $builder): void

protected function eventClass(): Attribute
{
return Attribute::make(get: fn (): string => 'Backstage\Mails\Events\Mail' . Str::studly($this->type->value));
return Attribute::make(get: fn (): string => 'Backstage\Mails\Events\Mail'.Str::studly($this->type->value));
}
}
2 changes: 1 addition & 1 deletion src/Notifications/SpamComplaintNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getMessage(): string
'馃敟', '馃Н', '鈥硷笍', '鈦夛笍', '馃敶', '馃摚', '馃槄', '馃サ',
]);

return $emoji . ' mail has bounced';
return $emoji.' mail has bounced';
}

public function toDiscord(): DiscordMessage
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function setUp(): void
parent::setUp();

Factory::guessFactoryNamesUsing(
fn (string $modelName): string => 'Backstage\\Mails\\Database\\Factories\\' . class_basename($modelName) . 'Factory'
fn (string $modelName): string => 'Backstage\\Mails\\Database\\Factories\\'.class_basename($modelName).'Factory'
);

$this->loadMigrations();
Expand Down Expand Up @@ -57,7 +57,7 @@ public function getEnvironmentSetUp($app): void
protected function loadMigrations(): void
{
$filesystem = new Filesystem;
$migrationFiles = $filesystem->files(__DIR__ . '/../database/migrations/');
$migrationFiles = $filesystem->files(__DIR__.'/../database/migrations/');

// Sorting to ensure migrations run in the correct order
usort($migrationFiles, fn ($a, $b): int => strcmp((string) $a->getFilename(), (string) $b->getFilename()));
Expand Down