diff --git a/README.md b/README.md index b80eae5..35791fb 100644 --- a/README.md +++ b/README.md @@ -239,9 +239,6 @@ Additionally, it has all the methods of the [Taskable](#taskable) interface. // Create a new task within the taskable. $taskable->createTask(string $taskName): Task; -// Remove the last task from the taskable and add another in its place. -$taskable->replaceLastTask(Task $task): void; - $taskable->getTasks(): array; $taskable->getLastTask(): ?Task; diff --git a/src/Concerns/HasTasks.php b/src/Concerns/HasTasks.php index 3fedc8c..3ec3679 100644 --- a/src/Concerns/HasTasks.php +++ b/src/Concerns/HasTasks.php @@ -22,13 +22,6 @@ public function createTask(string $taskName): Task return $task; } - public function replaceLastTask(Task $task): void - { - array_pop($this->tasks); - - $this->tasks[] = $task; - } - /** * @return array */ diff --git a/src/Contracts/Taskable.php b/src/Contracts/Taskable.php index 1cd2463..efbf1ff 100644 --- a/src/Contracts/Taskable.php +++ b/src/Contracts/Taskable.php @@ -10,8 +10,6 @@ interface Taskable { public function createTask(string $taskName): Task; - public function replaceLastTask(Task $task): void; - /** * @return array */ diff --git a/src/Services/TimeWardenManager.php b/src/Services/TimeWardenManager.php index e0e02e0..3f083bf 100644 --- a/src/Services/TimeWardenManager.php +++ b/src/Services/TimeWardenManager.php @@ -75,10 +75,9 @@ public function task(string $taskName): self /** @var Task|null $lastTask */ $lastTask = $taskable->getLastTask(); - // If the last task was never started, we overwrite it + // If the last task was never started, we replace its name with `$taskName` if ($lastTask instanceof Task && ! $lastTask->hasStarted()) { - $taskable->replaceLastTask(new Task($taskName, $taskable)); - + $lastTask->name = $taskName; } else { // If there is a task, but it has already started, we stop it if ($lastTask instanceof Task && $lastTask->hasStarted()) { diff --git a/src/Support/Facades/TimeWarden.php b/src/Support/Facades/TimeWarden.php index 5cef184..a29283c 100644 --- a/src/Support/Facades/TimeWarden.php +++ b/src/Support/Facades/TimeWarden.php @@ -19,7 +19,6 @@ * * Taskable methods: * @method static Task createTask(string $taskName) - * @method static void replaceLastTask(Task $task) * @method static array getTasks(string $taskName) * @method static Task|null getLastTask() * @method static float getDuration() diff --git a/tests/Contracts/TaskableTest.php b/tests/Contracts/TaskableTest.php index af27b41..d74865b 100644 --- a/tests/Contracts/TaskableTest.php +++ b/tests/Contracts/TaskableTest.php @@ -4,7 +4,6 @@ use Tomloprod\TimeWarden\Concerns\HasTasks; use Tomloprod\TimeWarden\Contracts\Taskable; -use Tomloprod\TimeWarden\Task; beforeEach(function (): void { $this->tasksClass = new class implements Taskable @@ -20,20 +19,6 @@ ->toContain($task); }); -it('can replace the last task', function (): void { - $task1 = $this->tasksClass->createTask('TaskName1'); - - $task2 = new Task('TaskName2', $this->tasksClass); - - $this->tasksClass->replaceLastTask($task2); - - expect($this->tasksClass->getTasks()) - ->not->toContain($task1); - - expect($this->tasksClass->getTasks()) - ->toContain($task2); -}); - it('can retrieve the last task', function (): void { $task1 = $this->tasksClass->createTask('TaskName1'); $task2 = $this->tasksClass->createTask('TaskName2'); diff --git a/tests/GroupTest.php b/tests/GroupTest.php index 9db4d2e..36a3009 100644 --- a/tests/GroupTest.php +++ b/tests/GroupTest.php @@ -3,7 +3,6 @@ declare(strict_types=1); use Tomloprod\TimeWarden\Group; -use Tomloprod\TimeWarden\Task; it('can be created with a name', function (): void { $group = new Group('GroupName'); @@ -20,19 +19,6 @@ expect($task->getTaskable())->toBe($group); }); -it('can replace the last task', function (): void { - $group = new Group('GroupName'); - - $task1 = $group->createTask('TaskName1'); - $task2 = new Task('TaskName2', $group); - - $group->replaceLastTask($task2); - - expect($group->getTasks())->not->toContain($task1); - - expect($group->getTasks())->toContain($task2); -}); - it('can start the last task if it exists', function (): void { $group = new Group('GroupName'); $task = $group->createTask('TaskName');