refactor exceptions

This commit is contained in:
DavidBadura
2015-04-06 21:13:02 +00:00
parent ec8ab39e7c
commit 0ab45fae1f
11 changed files with 189 additions and 88 deletions

View File

@@ -0,0 +1,98 @@
<?php
namespace DavidBadura\Taskwarrior\Exception;
use Symfony\Component\Process\Process;
/**
* @author David Badura <d.a.badura@gmail.com>
*/
class CommandException extends TaskwarriorException
{
/**
* @var string
*/
private $command;
/**
* @var int
*/
private $exitCode;
/**
* @var string
*/
private $output;
/**
* @var string
*/
private $errorOutput;
/**
* @param Process $process
*/
public function __construct(Process $process)
{
$this->command = $process->getCommandLine();
$this->exitCode = $process->getExitCode();
$this->output = $process->getOutput();
$this->errorOutput = $process->getErrorOutput();
if (!$message = $this->getCleanErrorOutput()) {
$message = $this->output;
}
parent::__construct($message, $this->getExitCode());
}
/**
* @return string
*/
public function getCommand()
{
return $this->command;
}
/**
* @return int
*/
public function getExitCode()
{
return $this->exitCode;
}
/**
* @return string
*/
public function getOutput()
{
return $this->output;
}
/**
* @return string
*/
public function getErrorOutput()
{
return $this->errorOutput;
}
/**
* @return string
*/
public function getCleanErrorOutput()
{
$message = '';
foreach (explode("\n", $this->errorOutput) as $line) {
if (strpos($line, 'Using alternate') === 0 || strpos($line, 'Configuration override') === 0) {
continue;
}
$message .= $line . "\n";
}
return trim($message);
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace DavidBadura\Taskwarrior\Exception;
/**
* @author David Badura <d.a.badura@gmail.com>
*/
class DatetimeParseException extends TaskwarriorException
{
}

View File

@@ -0,0 +1,10 @@
<?php
namespace DavidBadura\Taskwarrior\Exception;
/**
* @author David Badura <d.a.badura@gmail.com>
*/
class RecurringParseException extends TaskwarriorException
{
}

View File

@@ -0,0 +1,10 @@
<?php
namespace DavidBadura\Taskwarrior\Exception;
/**
* @author David Badura <badura@simplethings.de>
*/
class TaskwarriorException extends \Exception
{
}