public function toArray()
{
$hasMultipleNotifications = $this->isMultidimensionalArray($this->notifications);
// If the builder is handling a single notification
// we will validate only it
if (!$hasMultipleNotifications) {
$this->setDate();
if ($this->hasRequiredFields($this->notifications)) {
return $this->notifications;
}
}
// If has multiple Notifications
// we will validate one by one
if ($hasMultipleNotifications) {
$allow = [];
foreach ($this->notifications as $index => $notification) {
$allow[$index] = $this->hasRequiredFields($notification);
}
if (!in_array(false, $allow)) {
return $this->notifications;
}
}
$error = 'The fields: ' . implode(',', $this->getRequiredFields()) . ' are required';
throw new NotificationBuilderException($error);
}