. */ declare(strict_types=1); namespace FireflyIII\Exceptions; use Exception; use FireflyIII\Support\Calendar\Periodicity; use Throwable; /** * Class IntervalException */ final class IntervalException extends Exception { public readonly array $availableIntervals; public readonly Periodicity $periodicity; protected $message = 'The periodicity %s is unknown. Choose one of available periodicity: %s'; public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null) { parent::__construct($message, $code, $previous); $this->availableIntervals = []; $this->periodicity = Periodicity::Monthly; } /** * @param Periodicity $periodicity * @param array $intervals * @param int $code * @param Throwable|null $previous * * @return IntervalException */ public static function unavailable( Periodicity $periodicity, array $intervals, int $code = 0, ?Throwable $previous = null ): IntervalException { $message = sprintf( 'The periodicity %s is unknown. Choose one of available periodicity: %s', $periodicity->name, join(', ', $intervals) ); $exception = new IntervalException($message, $code, $previous); $exception->periodicity = $periodicity; $exception->availableIntervals = $intervals; return $exception; } }