You are here

protected function SmsMessageProcessor::ensureReports in SMS Framework 8

Same name and namespace in other branches
  1. 2.x src/EventSubscriber/SmsMessageProcessor.php \Drupal\sms\EventSubscriber\SmsMessageProcessor::ensureReports()
  2. 2.1.x src/EventSubscriber/SmsMessageProcessor.php \Drupal\sms\EventSubscriber\SmsMessageProcessor::ensureReports()

Ensures there is a result, and reports for each recipient.

Parameters

\Drupal\sms\Message\SmsMessageInterface $sms_message: A message to validate.

Throws

\Drupal\sms\Exception\SmsPluginReportException Thrown if result or reports are invalid.

2 calls to SmsMessageProcessor::ensureReports()
SmsMessageProcessor::ensureReportsPostprocess in src/EventSubscriber/SmsMessageProcessor.php
Ensures there is a result, and reports for each recipient.
SmsMessageProcessor::ensureReportsPreprocess in src/EventSubscriber/SmsMessageProcessor.php
Ensures there is a result, and reports for each recipient.

File

src/EventSubscriber/SmsMessageProcessor.php, line 117

Class

SmsMessageProcessor
Handles messages before they are processed by queue(), send(), or incoming().

Namespace

Drupal\sms\EventSubscriber

Code

protected function ensureReports(SmsMessageInterface $sms_message) {
  $result = $sms_message
    ->getResult();
  if (!$result instanceof SmsMessageResultInterface) {
    throw new SmsPluginReportException('Missing result for message.');
  }
  $message_recipients = $sms_message
    ->getRecipients();
  $result_recipients = array_map(function (SmsDeliveryReportInterface $report) {
    return $report
      ->getRecipient();
  }, $result
    ->getReports());
  $difference_count = count(array_diff($message_recipients, $result_recipients));
  if ($difference_count) {
    throw new SmsPluginReportException(sprintf('Missing reports for %s recipient(s).', $difference_count));
  }
}