Skip to content

Commit

Permalink
Merge pull request #2 from tomloprod/ref/empty-tasks-substitution-system
Browse files Browse the repository at this point in the history
ref: replace task substitution system
  • Loading branch information
tomloprod authored May 20, 2024
2 parents bfe97c0 + 7aa67dc commit c5e62ea
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 45 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 0 additions & 7 deletions src/Concerns/HasTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<Task>
*/
Expand Down
2 changes: 0 additions & 2 deletions src/Contracts/Taskable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ interface Taskable
{
public function createTask(string $taskName): Task;

public function replaceLastTask(Task $task): void;

/**
* @return array<Task>
*/
Expand Down
5 changes: 2 additions & 3 deletions src/Services/TimeWardenManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
1 change: 0 additions & 1 deletion src/Support/Facades/TimeWarden.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*
* Taskable methods:
* @method static Task createTask(string $taskName)
* @method static void replaceLastTask(Task $task)
* @method static array<Task> getTasks(string $taskName)
* @method static Task|null getLastTask()
* @method static float getDuration()
Expand Down
15 changes: 0 additions & 15 deletions tests/Contracts/TaskableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand Down
14 changes: 0 additions & 14 deletions tests/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down

0 comments on commit c5e62ea

Please sign in to comment.