Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
CaReS0107 authored and github-actions[bot] committed Jun 27, 2023
1 parent 071ebd4 commit 71c401b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
4 changes: 1 addition & 3 deletions src/Constraints/HoursSchedulerCheckerConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

namespace Binarcode\LaravelMailator\Constraints;

use Binarcode\LaravelMailator\Models\MailatorLog;
use Binarcode\LaravelMailator\Models\MailatorSchedule;
use Carbon\Carbon;
use Illuminate\Support\Collection;

class HoursSchedulerCheckerConstraint implements SendScheduleConstraint
{
public function canSend(MailatorSchedule $schedule, Collection $logs): bool
{
if (!$schedule->hasPrecision()) {
if (! $schedule->hasPrecision()) {
return true;
}

Expand Down
26 changes: 14 additions & 12 deletions src/Models/Concerns/ConstraintsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function configurationsPasses(): bool
WeeklyConstraint::class,
HoursSchedulerCheckerConstraint::class,
])
->map(fn($class) => app($class))
->every(fn(SendScheduleConstraint $event) => $event->canSend($this, $this->logs));
->map(fn ($class) => app($class))
->every(fn (SendScheduleConstraint $event) => $event->canSend($this, $this->logs));
}

public function whenPasses(): bool
Expand All @@ -49,18 +49,20 @@ public function whenPasses(): bool
public function eventsPasses(): bool
{
return collect($this->constraints)
->map(fn(string $event) => unserialize($event))
->filter(fn($event) => is_subclass_of($event, SendScheduleConstraint::class))
->filter(fn(SendScheduleConstraint $event) => $event->canSend($this,
$this->logs))->count() === collect($this->constraints)->count();
->map(fn (string $event) => unserialize($event))
->filter(fn ($event) => is_subclass_of($event, SendScheduleConstraint::class))
->filter(fn (SendScheduleConstraint $event) => $event->canSend(
$this,
$this->logs
))->count() === collect($this->constraints)->count();
}

public function constraintsDescriptions(): array
{
try {
return collect($this->constraints)
->map(fn(string $event) => unserialize($event))
->filter(fn($event) => is_subclass_of($event, Descriptionable::class))
->map(fn (string $event) => unserialize($event))
->filter(fn ($event) => is_subclass_of($event, Descriptionable::class))
->reduce(function ($base, Descriptionable $descriable) {
return array_merge($base, $descriable::conditions());
}, []);
Expand All @@ -75,10 +77,10 @@ public function constraintsNotSatisfiedDescriptions(): array
{
try {
return collect($this->constraints)
->map(fn(string $event) => unserialize($event))
->filter(fn($event) => is_subclass_of($event, Descriptionable::class))
->filter(fn($event) => is_subclass_of($event, SendScheduleConstraint::class))
->filter(fn($event) => !$event->canSend($this, $this->logs))
->map(fn (string $event) => unserialize($event))
->filter(fn ($event) => is_subclass_of($event, Descriptionable::class))
->filter(fn ($event) => is_subclass_of($event, SendScheduleConstraint::class))
->filter(fn ($event) => ! $event->canSend($this, $this->logs))
->reduce(function ($base, Descriptionable $descriable) {
return array_merge($base, $descriable::conditions());
}, []);
Expand Down
30 changes: 15 additions & 15 deletions src/Models/MailatorSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public function mailable(Mailable $mailable): self
{
if ($mailable instanceof Constraintable) {
collect($mailable->constraints())
->filter(fn($constraint) => $constraint instanceof SendScheduleConstraint)
->each(fn(SendScheduleConstraint $constraint) => $this->constraint($constraint));
->filter(fn ($constraint) => $constraint instanceof SendScheduleConstraint)
->each(fn (SendScheduleConstraint $constraint) => $this->constraint($constraint));
}

$this->mailable_class = serialize($mailable);
Expand Down Expand Up @@ -337,7 +337,7 @@ public function recipients(...$recipients): self
{
$this->recipients = array_merge(collect($recipients)
->flatten()
->filter(fn($email) => $this->ensureValidEmail($email))
->filter(fn ($email) => $this->ensureValidEmail($email))
->unique()
->toArray(), $this->recipients ?? []);

Expand All @@ -363,15 +363,15 @@ public function shouldSend(): bool
try {
$this->load('logs');

if (!$this->configurationsPasses()) {
if (! $this->configurationsPasses()) {
return false;
}

if (!$this->whenPasses()) {
if (! $this->whenPasses()) {
return false;
}

if (!$this->eventsPasses()) {
if (! $this->eventsPasses()) {
if ($this->isStopable()) {
$this->markComplete();
}
Expand All @@ -391,7 +391,7 @@ public function shouldSend(): bool

public function executeWhenPasses(bool $now = false): void
{
if (!$this->save()) {
if (! $this->save()) {
return;
}

Expand All @@ -402,7 +402,7 @@ public function executeWhenPasses(bool $now = false): void

public function execute(bool $now = false): void
{
if (!$this->save()) {
if (! $this->save()) {
return;
}

Expand Down Expand Up @@ -432,7 +432,7 @@ public static function run(): void

public function hasCustomAction(): bool
{
return !is_null($this->action);
return ! is_null($this->action);
}

public function getMailable(): ?Mailable
Expand Down Expand Up @@ -487,13 +487,13 @@ public function markAsFailed(string $failureReason): self
public function getRecipients(): array
{
return collect($this->recipients)
->filter(fn($email) => $this->ensureValidEmail($email))
->filter(fn ($email) => $this->ensureValidEmail($email))
->toArray();
}

protected function ensureValidEmail(string $email): bool
{
return !Validator::make(
return ! Validator::make(
compact('email'),
['email' => 'required|email']
)->fails();
Expand Down Expand Up @@ -557,7 +557,7 @@ public function markComplete(): self

public function isCompleted(): bool
{
return !is_null($this->completed_at);
return ! is_null($this->completed_at);
}

public function failedLastTimes(int $times): bool
Expand All @@ -579,12 +579,12 @@ public function timestampTarget(): ?CarbonInterface

public function isRepetitive(): bool
{
return !$this->isOnce();
return ! $this->isOnce();
}

public function wasSentOnce(): bool
{
return !is_null($this->last_sent_at);
return ! is_null($this->last_sent_at);
}

public function getConstraints(): ConstraintsCollection
Expand All @@ -594,7 +594,7 @@ public function getConstraints(): ConstraintsCollection

public function save(array $options = [])
{
if (!$this->isUnique()) {
if (! $this->isUnique()) {
return parent::save($options);
}

Expand Down
1 change: 0 additions & 1 deletion tests/Feature/WithWeekendsConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Binarcode\LaravelMailator\Tests\Feature;

use Binarcode\LaravelMailator\Constraints\AfterConstraint;
use Binarcode\LaravelMailator\Models\MailatorSchedule;
use Binarcode\LaravelMailator\Tests\Fixtures\InvoiceReminderMailable;
use Binarcode\LaravelMailator\Tests\TestCase;
Expand Down

0 comments on commit 71c401b

Please sign in to comment.