withErrorCode(self::MIGRATION_FAILED) ->withMessage(__(sprintf('Migration failed: %s', $error), 'mailpoet')); } public static function databaseError(string $error): InvalidStateException { return InvalidStateException::create() ->withErrorCode(self::DATABASE_ERROR) ->withMessage(__(sprintf('Database error: %s', $error), 'mailpoet')); } public static function apiMethodNotAllowed(): UnexpectedValueException { return UnexpectedValueException::create() ->withStatusCode(405) ->withErrorCode(self::API_METHOD_NOT_ALLOWED) ->withMessage(__('Method not allowed.', 'mailpoet')); } public static function apiNoJsonBody(): UnexpectedValueException { return UnexpectedValueException::create() ->withErrorCode(self::API_NO_JSON_BODY) ->withMessage(__('No JSON body passed.', 'mailpoet')); } public static function jsonNotObject(string $json): UnexpectedValueException { return UnexpectedValueException::create() ->withErrorCode(self::JSON_NOT_OBJECT) ->withMessage(__(sprintf("JSON string '%s' doesn't encode an object.", $json), 'mailpoet')); } public static function workflowNotFound(int $id): NotFoundException { return NotFoundException::create() ->withErrorCode(self::WORKFLOW_NOT_FOUND) ->withMessage(__(sprintf("Workflow with ID '%s' not found.", $id), 'mailpoet')); } public static function workflowRunNotFound(int $id): NotFoundException { return NotFoundException::create() ->withErrorCode(self::WORKFLOW_RUN_NOT_FOUND) ->withMessage(__(sprintf("Workflow run with ID '%s' not found.", $id), 'mailpoet')); } public static function workflowStepNotFound(string $id): NotFoundException { return NotFoundException::create() ->withErrorCode(self::WORKFLOW_STEP_NOT_FOUND) ->withMessage(__(sprintf("Workflow step with ID '%s' not found.", $id), 'mailpoet')); } public static function workflowTriggerNotFound(int $workflowId, string $key): NotFoundException { return NotFoundException::create() ->withErrorCode(self::WORKFLOW_TRIGGER_NOT_FOUND) ->withMessage(__(sprintf("Workflow trigger with key '%s' not found in workflow ID '%s'.", $key, $workflowId), 'mailpoet')); } public static function workflowRunNotRunning(int $id, string $status): InvalidStateException { return InvalidStateException::create() ->withErrorCode(self::WORKFLOW_RUN_NOT_RUNNING) ->withMessage(__(sprintf("Workflow run with ID '%s' is not running. Status: %s", $id, $status), 'mailpoet')); } public static function subjectNotFound(string $key): NotFoundException { return NotFoundException::create() ->withErrorCode(self::SUBJECT_NOT_FOUND) ->withMessage(__(sprintf("Subject with key '%s' not found.", $key), 'mailpoet')); } public static function subjectLoadFailed(string $key, array $args): InvalidStateException { return InvalidStateException::create() ->withErrorCode(self::SUBJECT_LOAD_FAILED) ->withMessage(__(sprintf("Subject with key '%s' and args '%s' failed to load.", $key, Json::encode($args)), 'mailpoet')); } public static function multipleSubjectsFound(string $key): InvalidStateException { return InvalidStateException::create() ->withErrorCode(self::MULTIPLE_SUBJECTS_FOUND) ->withMessage(__(sprintf("Multiple subjects with key '%s' found, only one expected.", $key), 'mailpoet')); } }