refactor: clean up code and remove some dependencies
This commit is contained in:
62
src/Taskwarrior/Commands/TodoStrategy.php
Normal file
62
src/Taskwarrior/Commands/TodoStrategy.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
|
||||
class TodoStrategy implements IStrategy {
|
||||
|
||||
public function __construct(TaskwarriorConfig $config){
|
||||
$this->config = $config;
|
||||
$this->cmd[] = $this->config->taskBin();
|
||||
}
|
||||
|
||||
public function add(Task $task){
|
||||
$this->cmd[] = 'add';
|
||||
|
||||
if($task->getDescription() != null){
|
||||
$this->cmd[] = sprintf('"%s"', $task->getDescription());
|
||||
}
|
||||
|
||||
if($task->getCategories() != null){
|
||||
$categories = implode(' +', $task->getCategories());
|
||||
$this->cmd[] = $categories;
|
||||
}
|
||||
|
||||
if($task->getDue() != null){
|
||||
$this->cmd[] = $task->getDue('Y-m-dTH:i:s');
|
||||
}
|
||||
|
||||
if($task->getRecurrence() != null){
|
||||
$rrule = $task->getRecurrence()->getParts();
|
||||
$this->cmd[] = sprintf('recur:%s', $rrule['FREQ']);
|
||||
if(isset($rrule['UNTIL'])){
|
||||
$this->cmd[] = sprintf('until:%s', $rrule['UNTIL']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($task->getStatus() != null){
|
||||
$this->cmd[] = sprintf('status:%s', $task->getStatus());
|
||||
}
|
||||
|
||||
return $this->executeCommand($cmd);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private function executeCommand($command){
|
||||
|
||||
|
||||
$cmdString = implode(' ', $command);
|
||||
$process = new Process($cmdString);
|
||||
|
||||
$process->run();
|
||||
|
||||
if(!$process->isSuccessful()){
|
||||
throw new TaskwarriorCommandLineException($process);
|
||||
}
|
||||
|
||||
return $process->getOutput();
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user