Automattic\WooCommerce\Admin\RemoteInboxNotifications

RemoteInboxNotificationsDataSourcePoller::validate_action()privateWC 1.0

Validate the action.

Method of the class: RemoteInboxNotificationsDataSourcePoller{}

No Hooks.

Return

true|false. The result of the validation.

Usage

// private - for code of main (parent) class only
$result = $this->validate_action( $action, $url );
$action(object) (required)
The action to validate.
$url(string) (required)
The url of the feed containing the action (for error reporting).

RemoteInboxNotificationsDataSourcePoller::validate_action() code WC 9.3.3

private function validate_action( $action, $url ) {
	$logger         = self::get_logger();
	$logger_context = array( 'source' => $url );

	if ( ! isset( $action->locales ) || ! is_array( $action->locales ) ) {
		$logger->error(
			'Action is invalid because it has empty or missing locales in feed',
			$logger_context
		);
		// phpcs:ignore
		$logger->error( print_r( $action, true ), $logger_context );

		return false;
	}

	if ( null === SpecRunner::get_action_locale( $action->locales ) ) {
		$logger->error(
			'Action is invalid because the locale could not be retrieved in feed',
			$logger_context
		);
		// phpcs:ignore
		$logger->error( print_r( $action, true ), $logger_context );

		return false;
	}

	if ( ! isset( $action->name ) ) {
		$logger->error(
			'Action is invalid because the name is missing in feed',
			$logger_context
		);
		// phpcs:ignore
		$logger->error( print_r( $action, true ), $logger_context );

		return false;
	}

	if ( ! isset( $action->status ) ) {
		$logger->error(
			'Action is invalid because the status is missing in feed',
			$logger_context
		);
		// phpcs:ignore
		$logger->error( print_r( $action, true ), $logger_context );

		return false;
	}

	return true;
}