refactor exceptions
This commit is contained in:
98
src/Exception/CommandException.php
Normal file
98
src/Exception/CommandException.php
Normal 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);
|
||||
}
|
||||
}
|
10
src/Exception/DatetimeParseException.php
Normal file
10
src/Exception/DatetimeParseException.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace DavidBadura\Taskwarrior\Exception;
|
||||
|
||||
/**
|
||||
* @author David Badura <d.a.badura@gmail.com>
|
||||
*/
|
||||
class DatetimeParseException extends TaskwarriorException
|
||||
{
|
||||
}
|
10
src/Exception/RecurringParseException.php
Normal file
10
src/Exception/RecurringParseException.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace DavidBadura\Taskwarrior\Exception;
|
||||
|
||||
/**
|
||||
* @author David Badura <d.a.badura@gmail.com>
|
||||
*/
|
||||
class RecurringParseException extends TaskwarriorException
|
||||
{
|
||||
}
|
10
src/Exception/TaskwarriorException.php
Normal file
10
src/Exception/TaskwarriorException.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace DavidBadura\Taskwarrior\Exception;
|
||||
|
||||
/**
|
||||
* @author David Badura <badura@simplethings.de>
|
||||
*/
|
||||
class TaskwarriorException extends \Exception
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user