From 014c986103a579ac3a22879e77eba1da20a48561 Mon Sep 17 00:00:00 2001 From: DavidBadura Date: Fri, 3 Apr 2015 14:39:19 +0000 Subject: [PATCH] refactor validation --- src/TaskManager.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/TaskManager.php b/src/TaskManager.php index d4a5e7b..c292fd0 100644 --- a/src/TaskManager.php +++ b/src/TaskManager.php @@ -44,6 +44,8 @@ class TaskManager */ public function save(Task $task) { + $this->validate($task); + if (!$task->getUuid()) { $this->add($task); } else { @@ -209,10 +211,6 @@ class TaskManager */ 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(), @@ -228,6 +226,17 @@ class TaskManager ); } + /** + * @param Task $task + * @throws TaskwarriorException + */ + private function validate(Task $task) + { + if ($task->isReccuring() && !$task->getRecurring()) { + throw new TaskwarriorException('You cannot remove the recurrence from a recurring task.'); + } + } + /** * @param Task $old * @param Task $new