<commit_before><?php

namespace KVZ\Laravel\SwitchableMail;

use Swift_Message;

class MailDriver
{
    /**
     * Determine mail driver for the given swift message.
     *
     * @param  \Swift_Message  $message
     * @return string|null
     */
    public static function forMessage(Swift_Message $message)
    {
        $recipientsDomains = static::getMessageRecipientsDomains($message);

        return key(array_filter(
            config('switchable-mail', []),
            function ($value) use ($recipientsDomains) {
                return count(array_intersect($value, $recipientsDomains)) > 0;
            },
            ARRAY_FILTER_USE_BOTH
        ));
    }

    /**
     * Get domains for the recipients of message.
     *
     * @param  \Swift_Message  $message
     * @return array
     */
    public static function getMessageRecipientsDomains(Swift_Message $message)
    {
        return array_values(array_unique(array_map(
            function ($address) {
                return strtolower(last(explode('@', $address)));
            },
            static::getMessageRecipients($message)
        )));
    }

    /**
     * Get recipients for the given message.
     *
     * @param  \Swift_Message  $message
     * @return array
     */
    public static function getMessageRecipients(Swift_Message $message)
    {
        return array_keys(array_merge(
            (array) $message->getTo(),
            (array) $message->getReplyTo(),
            (array) $message->getCc(),
            (array) $message->getBcc()
        ));
    }
}
<commit_msg>Improve MailDriver::forMessage<commit_after><?php

namespace KVZ\Laravel\SwitchableMail;

use Swift_Message;

class MailDriver
{
    /**
     * Determine mail driver for the given swift message.
     *
     * @param  \Swift_Message  $message
     * @return string|null
     */
    public static function forMessage(Swift_Message $message)
    {
        if ($multiDrivers = config('switchable-mail', [])) {
            $recipientsDomains = static::getMessageRecipientsDomains($message);

            return key(array_filter(
                $multiDrivers,
                function ($value) use ($recipientsDomains) {
                    return count(array_intersect($value, $recipientsDomains)) > 0;
                },
                ARRAY_FILTER_USE_BOTH
            ));
        }
    }

    /**
     * Get domains for the recipients of message.
     *
     * @param  \Swift_Message  $message
     * @return array
     */
    public static function getMessageRecipientsDomains(Swift_Message $message)
    {
        return array_values(array_unique(array_map(
            function ($address) {
                return strtolower(last(explode('@', $address)));
            },
            static::getMessageRecipients($message)
        )));
    }

    /**
     * Get recipients for the given message.
     *
     * @param  \Swift_Message  $message
     * @return array
     */
    public static function getMessageRecipients(Swift_Message $message)
    {
        return array_keys(array_merge(
            (array) $message->getTo(),
            (array) $message->getReplyTo(),
            (array) $message->getCc(),
            (array) $message->getBcc()
        ));
    }
}

{'fraction_non_alphanumeric': 0.11080246913580247, 'fraction_numerical': 0.0006172839506172839, 'mean_word_length': 2.069128787878788, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1412645', 'n_tokens_mistral': 941, 'n_tokens_neox': 889, 'n_words': 184}