Skip to content

Instantly share code, notes, and snippets.

@pentagonal
Last active September 14, 2017 19:41
Show Gist options
  • Save pentagonal/af783b1da2ffaec3253ce989ede66ef7 to your computer and use it in GitHub Desktop.
Save pentagonal/af783b1da2ffaec3253ce989ede66ef7 to your computer and use it in GitHub Desktop.
Task State Base
<?php
declare(strict_type=1);
namespace Pentagonal\Gist\Task\Abstracts;
use Pentagonal\Gist\Task\Interfaces\TaskInterface;
use InvalidArgumentException;
/**
* class TaskAbstract
* @package Pentagonal\Gist\Task\Abstracts
*/
abstract class TaskAbstract implements TaskInterface
{
/**
* @var int current state
*/
private $currentState = self::NO_STATE;
/**
* @var int[] available state
*/
protected $availableState = [
self::NO_STATE,
self::PENDING_STATE,
self::COMPLETE_STATE,
self::SKIP_STATE,
self::FAIL_STATE,
self::CANCEL_STATE
];
/**
* {@inheritdoc}
*/
final public function setState(int $state)
{
if (! in_array($state, $this->availableState, true)) {
throw new InvalidArgumentException(
sprintf(
'State (%d) is not a valid state.',
$state
),
E_WARNING
);
}
$this->currentState = $state;
}
/**
* {@inheritdoc}
*/
final public function getState() : int
{
return $this->currentState;
}
}
<?php
declare(strict_type=1);
namespace Pentagonal\Gist\Task\Interfaces;
/**
* interface TaskInterface
* @package Pentagonal\Gist\Task\Interfaces
*/
interface TaskInterface
{
/**
* List State of Task
*/
const NO_STATE = -1;
const PENDING_STATE = 0;
const COMPLETE_STATE = 1;
const SKIP_STATE = 2;
const FAIL_STATE = 3;
const CANCEL_STATE = 4;
/**
* Get Task name
*
* @return int the current state
*/
public function getState() : int;
/**
* Set state
*
* @param int $state set current the state
*/
public function setState(int $state);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment