Use enum for undo mode

This commit is contained in:
Jan Böhmer 2023-06-18 21:26:28 +02:00
parent 218b0adb8f
commit 8a20584e27
14 changed files with 140 additions and 180 deletions

View file

@ -46,27 +46,19 @@ use InvalidArgumentException;
class EventUndoHelper
{
final public const MODE_UNDO = 'undo';
final public const MODE_REVERT = 'revert';
protected const ALLOWED_MODES = [self::MODE_REVERT, self::MODE_UNDO];
protected ?AbstractLogEntry $undone_event = null;
protected string $mode = self::MODE_UNDO;
protected EventUndoMode $mode = EventUndoMode::UNDO;
public function __construct()
{
}
public function setMode(string $mode): void
public function setMode(EventUndoMode $mode): void
{
if (!in_array($mode, self::ALLOWED_MODES, true)) {
throw new InvalidArgumentException('Invalid mode passed!');
}
$this->mode = $mode;
}
public function getMode(): string
public function getMode(): EventUndoMode
{
return $this->mode;
}