@throws \InvalidArgumentException if recipients list is empty
@throws \InvalidArgumentException if recipients list has at least one invalid recipient

@param array $recipients

@return void
778262
protected function validateRecipients(array $recipients)
    {
        if (true == empty($recipients)) {
            throw new \InvalidArgumentException('Recipients list should not be empty');
        }

        foreach ($recipients as $recipient) {
            if (true == is_string($recipient) && $this->isValidMail($recipient)) {
                continue;
            }

            throw new \InvalidArgumentException(sprintf(
                'Given recipients list %s has invalid recipient %s',
                var_export($recipients, true),
                var_export($recipient, true)
            ));
        }
    }
1150184
public function setLoaders(array $loaders)
    {
        $this->loaders = array();
        foreach ($loaders as $type=>$loader) {
            if (!$loader instanceof ResourceLoaderInterface) {
                throw new \InvalidArgumentException("Not a valid resource loader.");
            }
            $this->loaders[$type] = $loader;
        }
    }
1254277
public function setRoles(array $roles)
    {
        $this->roleIdentifiers = [];
        $this->roles = [];
        foreach ($roles as $role) {
            if (!$role instanceof Role) {
                throw new \InvalidArgumentException(sprintf('setRoles() only accepts an array of %s instances, given: "%s"', Role::class, gettype($role)), 1397125997);
            }
            $this->addRole($role);
        }
    }
1050781
public function removeAddresses($addresses)
    {
        $this->setCachedValue(null);
        foreach ((array) $addresses as $address) {
            unset($this->mailboxes[$address]);
        }
    }
1302251
protected function flushCache(array $invalidates): void
    {
        if (\count($invalidates) > 0) {
            if ($this->cache instanceof AdapterInterface && null !== $this->context) {
                $this->cache->clearByPrefixes($invalidates);
            } elseif (null !== $this->cache) {
                $this->cache->clear();
            }

            if ($this->sim instanceof CacheSecurityIdentityManagerInterface) {
                $this->sim->invalidateCache();
            }
        }
    }
829983
public function setRoutes(array $routes) {

	    foreach($routes as $route) {

	        if(!$route instanceof Route) {
	            throw new \InvalidArgumentException(sprintf("'%s' is not a Route instance.", $route));
            }

            $this->addRoute($route);

        }

    }
432996
private function filterNameAddresses(array $recipients)
    {
        $filtered = [];

        foreach ($recipients as $address => $name) {
            if ($this->isWhitelisted($address)) {
                $filtered[$address] = $name;
            }
        }

        return $filtered;
    }
916633
protected function assertIterable($subject, $msg): void
    {
        $iterable = function_exists('is_iterable')
            ? is_iterable($subject)
            : is_array($subject) || $subject instanceof Traversable;
        
        if (!$iterable) {
            throw new InvalidArgumentException($msg);
        }
    }
583799
public function setBcc($email)
    {
        if (is_string($email)) {
            // Means we have a straight email
            $email = [ $email ];
        }

        if (!is_array($email)) {
            throw new InvalidArgumentException(
                'Must be an array of BCC recipients.'
            );
        }

        $this->bcc = [];

        // At this point, `$email` can be an _email array_ or an _array of emails_...
        if (isset($email['email'])) {
            // Means we're not dealing with multiple emails
            $this->addBcc($email);
        } else {
            foreach ($email as $recipient) {
                $this->addBcc($recipient);
            }
        }

        return $this;
    }
272702
protected function setHeaders(array $headers)
    {
        $this->headerNames = $this->headerValues = [];

        foreach ($headers as $name => $value) {
            if (!is_array($value)) {
                $value = [$value];
            }

            if (in_array(false, array_map('is_string', $value))) {
                throw new InvalidArgumentException('Header value must be string or array of string.');
            }

            $lowerName = strtolower($name);
            $this->headerNames[$lowerName] = $name;
            $this->headerValues[$lowerName] = $value;
        }
    }
477674
protected function sendHeaders(array $headers = [])
    {
        ini_set('expose_php', 0);

        // collect headers that already sent
        foreach (headers_list() as $header) {
            $headerParts = explode(':', $header);
            $headerParts = array_map('trim', $headerParts);
            $headers[ $headerParts[ 0 ] ] = $headerParts[ 1 ];
            header_remove($header[ 0 ]);
        }

        if (count($headers)) {
            $this->headers = array_merge($this->headers, $headers);
        }

        if ($this->statusCode === 204) {
            $this->statusCode = 200;
            $this->reasonPhrase = 'OK';
        }

        $this->sendHeaderStatus($this->statusCode, $this->reasonPhrase, $this->protocol);

        foreach ($this->headers as $name => $value) {
            $this->sendHeader($name, $value);
        }
    }
1268649
public function addRecipient(Recipient $recipient)
    {
        if (!$recipient instanceof Device && !$recipient instanceof Topic) {
            throw new \UnexpectedValueException('currently phpFCM only supports topic and single device messages');
        }

        if (!isset($this->recipientType)) {
            $this->recipientType = get_class($recipient);
        }

        if ($this->recipientType !== get_class($recipient)) {
            throw new \InvalidArgumentException('mixed recepient types are not supported by FCM');
        }

        $this->recipients[] = $recipient;
        return $this;
    }
608690
public function broadcast($recipients = array())
	{
		// Get everyone subscribed
		$subscriptions = Subscription::all()
			->whereEquals('scope', $this->get('scope'))
			->whereEquals('scope_id', $this->get('scope_id'))
			->rows();

		foreach ($subscriptions as $subscription)
		{
			$recipients[] = array(
				'scope'    => 'user',
				'scope_id' => $subscription->get('user_id')
			);
		}

		$sent = array();

		// Do we have any recipients?
		foreach ($recipients as $receiver)
		{
			// Default to type 'user'
			if (!is_array($receiver))
			{
				$receiver = array(
					'scope'    => 'user',
					'scope_id' => $receiver
				);
			}

			// Make sure we have expected data
			if (!isset($receiver['scope'])
			 || !isset($receiver['scope_id']))
			{
				$receiver = array_values($receiver);

				$receiver['scope']    = $receiver[0];
				$receiver['scope_id'] = $receiver[1];
			}

			$key = $receiver['scope'] . '.' . $receiver['scope_id'];

			// No duplicate sendings
			if (in_array($key, $sent))
			{
				continue;
			}

			// Create a recipient object that ties a user to an activity
			$recipient = Recipient::blank()->set([
				'scope'    => $receiver['scope'],
				'scope_id' => $receiver['scope_id'],
				'log_id'   => $this->get('id'),
				'state'    => Recipient::STATE_PUBLISHED
			]);

			if (!$recipient->save())
			{
				return false;
			}

			$sent[] = $key;
		}

		return true;
	}
534089
public static function create(string $template, $recipients, Address $sender = null)
    {
        $email = new static($template);

        $recipients = is_array($recipients) ? $recipients : [$recipients];
        foreach ($recipients as $recipient) {
            $email->addRecipient($recipient);
        }

        if (null !== $sender) {
            $email->setSender($sender);
        }

        return $email;
    }
813557
private function isValidCountries(array $countries): void
    {
        if (!empty($countries)) {
            foreach ($countries as $country) {
                $this->isValidCountry($country);
            }
        }
    }
69298
public function setRevisions(array $revisions)
    {
        $this->revisions = new ArrayCollection();

        /** @var \Rcm\Entity\Revision $revision */
        foreach ($revisions as $revision) {
            if (!$revision instanceof Revision) {
                throw new InvalidArgumentException(
                    "Invalid Revision passed in.  Unable to set array"
                );
            }

            $this->revisions->set($revision->getRevisionId(), $revision);
        }
    }
921835
public function setMessages($messages)
	{
		if (!is_array($messages))
		{
			throw new InvalidArgumentException(sprintf(
				'Messages must be an array. Type of "%s" passed.',
				gettype($messages)
			));
		}

		$this->_messages = $messages;

		return $this;
	}