From c026f2b954c6eee47ae0fe5286e131c57edffb28 Mon Sep 17 00:00:00 2001 From: DavidBadura Date: Fri, 3 Apr 2015 14:36:58 +0000 Subject: [PATCH] lazy validation --- src/Task.php | 11 +++++------ src/TaskManager.php | 5 +++++ tests/TaskManagerTest.php | 2 ++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Task.php b/src/Task.php index 666f340..6277a7b 100644 --- a/src/Task.php +++ b/src/Task.php @@ -270,16 +270,15 @@ class Task /** * @param string|Recurring $recur - * @throws TaskwarriorException */ public function setRecurring($recur) { - if (is_string($recur)) { - $this->recur = new Recurring($recur); - } elseif ($recur instanceof Recurring) { + if ($recur instanceof Recurring) { $this->recur = $recur; - } elseif ($this->recur && is_null($recur)) { - throw new TaskwarriorException('You cannot remove the recurrence from a recurring task.'); + } elseif ($recur) { + $this->recur = new Recurring($recur); + } else { + $this->recur = null; } } diff --git a/src/TaskManager.php b/src/TaskManager.php index 0e6f90b..d4a5e7b 100644 --- a/src/TaskManager.php +++ b/src/TaskManager.php @@ -205,9 +205,14 @@ class TaskManager /** * @param Task $task + * @throws TaskwarriorException */ private function edit(Task $task) { + if ($task->isReccuring() && !$task->getRecurring()) { + throw new TaskwarriorException('You cannot remove the recurrence from a recurring task.'); + } + $this->taskwarrior->modify( [ 'description' => $task->getDescription(), diff --git a/tests/TaskManagerTest.php b/tests/TaskManagerTest.php index 12e4fec..945603a 100644 --- a/tests/TaskManagerTest.php +++ b/tests/TaskManagerTest.php @@ -541,6 +541,8 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase $this->taskManager->save($task1); $task1->setRecurring(null); + + $this->taskManager->save($task1); } public function testRecurringNull()