Skip to content

Commit

Permalink
fix: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
frknasir committed Nov 8, 2022
1 parent 9c6964e commit 9c8d891
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
20 changes: 10 additions & 10 deletions src/FrequencyEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

enum FrequencyEnum: string
{
CASE SECONDLY = 'SECONDLY';
CASE MINUTELY = 'MINUTELY';
CASE HOURLY = 'HOURLY';
CASE DAILY = 'DAILY';
CASE WEEKLY = 'WEEKLY';
CASE MONTHLY = 'MONTHLY';
CASE YEARLY = 'YEARLY';
case SECOND = 'SECONDLY';
case MINUTE = 'MINUTELY';
case HOUR = 'HOURLY';
case DAY = 'DAILY';
case WEEK = 'WEEKLY';
case MONTH = 'MONTHLY';
case YEAR = 'YEARLY';

/**
* Returns the values in an array.
*
*
* @return array
*/
public static function toArray(): array
{
return collect(self::cases())
->map(fn ($selfObj) => $selfObj->value)
->mapWithKeys(fn ($selfObj) => [$selfObj->value => $selfObj->name])
->toArray();
}
}
}
18 changes: 10 additions & 8 deletions src/Recurs.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ public function pauseRecurrence(bool $value = true)
*/
public function recurrenceIsActive(): bool
{
return $this->recurrence->status === 'active' && (
(!is_null($this->recurrence->ends_at) && ($this->recurrence->ends_at > now())) ||
(!is_null($this->recurrence->ends_after) && $this->nextRecurrence()) ||
(is_null($this->recurrence->ends_at) && is_null($this->recurrence->ends_after))
);
return ($this->recurrence?->starts_at >= now()) &&
$this->recurrence?->status === 'active' && (
(! is_null($this->recurrence->ends_at) && ($this->recurrence->ends_at >= now())) ||
(! is_null($this->recurrence->ends_after) && $this->nextRecurrence()) ||
(is_null($this->recurrence->ends_at) && is_null($this->recurrence->ends_after))
);
}

/**
Expand Down Expand Up @@ -189,14 +190,15 @@ public function lastRecurrence()

/**
* Ensure provided frequency is supported.
*
* @param string $frequency
*
* @param string $frequency
* @return void
*
* @throws \Exception
*/
public function ensuresFrequencyIsSupported(string $frequency)
{
if (!FrequencyEnum::tryFrom($frequency)) {
if (! FrequencyEnum::tryFrom($frequency)) {
throw new \Exception("{$frequency} is not supported by Redo(recurrence package)");
}
}
Expand Down
18 changes: 10 additions & 8 deletions stubs/database/factories/RecurrenceFactory.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<?php

namespace StarfolkSoftware\Gauge\Database\Factories;
namespace Database\Factories;

use App\Models\Recurrence;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Recurrence>
*/
class RecurrenceFactory extends Factory
{
protected $model = Recurrence::class;

/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
'team_id' => 1,
'recurrable_type' => 'App\\Models\\Task',
'recurrable_id' => 1,
'frequency' => 'DAILY',
'starts_at' => now(),
'starts_at' => now()->addHour(),
];
}
}
6 changes: 3 additions & 3 deletions tests/RecursTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

$task = Task::forceCreate(['title' => 'Task 1']);

$startsAt = now();
$startsAt = now()->addHour();

$task->makeRecurrable(
frequency: 'DAILY',
Expand All @@ -34,7 +34,7 @@

$task = Task::forceCreate(['title' => 'Task 1']);

$startsAt = now();
$startsAt = now()->addHour();

$task->makeRecurrable(
frequency: 'DAILY',
Expand Down Expand Up @@ -62,7 +62,7 @@

$task = Task::forceCreate(['title' => 'Task 1']);

$startsAt = now();
$startsAt = now()->addHour();

$task->makeRecurrable(
frequency: 'DAILY',
Expand Down

0 comments on commit 9c8d891

Please sign in to comment.