Replace hard-coded interval in RecurringRepository's create method with parameter
MODIFY
app/Http/Controllers/RecurringController.php
app/Http/Controllers/RecurringController.php
@@ -50,6 +50,7 @@ class RecurringController extends Controller
$recurring = $this->recurringRepository->create(
session('space')->id,
$request->type,
+ 'monthly',
(int) ltrim($request->input('day'), 0),
$request->input('end', null),
$request->input('tag', null),

MODIFY
app/Repositories/RecurringRepository.php
app/Repositories/RecurringRepository.php
@@ -22,6 +22,14 @@ class RecurringRepository
];
}
+ public function getSupportedIntervals(): array
+ {
+ return [
+ 'monthly',
+ 'daily'
+ ];
+ }
+
/**
* Grabs recurrings that checks all of the following statements
* targeted day is today, or in future if today is last day of the month
@@ -78,6 +86,7 @@ class RecurringRepository
public function create(
int $spaceId,
string $type,
+ string $interval,
int $day,
?string $endDate,
?int $tagId,
@@ -88,10 +97,14 @@ class RecurringRepository
throw new Exception('Unknown type "' . $type . '"');
}
+ if (!in_array($interval, $this->getSupportedIntervals())) {
+ throw new Exception('Unknown interval "' . $interval . '"');
+ }
+
return Recurring::create([
'space_id' => $spaceId,
'type' => $type,
- 'interval' => 'monthly',
+ 'interval' => $interval,
'day' => $day,
'starts_on' => date('Y-m-d'),
'ends_on' => $endDate,

MODIFY
tests/Unit/Repositories/RecurringRepositoryTest.php
tests/Unit/Repositories/RecurringRepositoryTest.php
@@ -21,7 +21,7 @@ class RecurringRepositoryTest extends TestCase
$spaceId = 1;
$tagId = 1;
- $recurring = $this->recurringRepository->create($spaceId, 'spending', 3, null, $tagId, 'Test', 10000);
+ $recurring = $this->recurringRepository->create($spaceId, 'spending', 'monthly', 3, null, $tagId, 'Foo', 10000);
$this->assertNotNull($recurring);
$this->assertEquals(10000, $recurring->amount);

Replace hard-coded interval in RecurringRepository's create method with parameter