<commit_before><?php

namespace Illuminate\Mail\Transport;

use Swift_Mime_Message;
use GuzzleHttp\ClientInterface;

class SparkPostTransport extends Transport
{
    /**
     * Guzzle client instance.
     *
     * @var \GuzzleHttp\ClientInterface
     */
    protected $client;

    /**
     * The SparkPost API key.
     *
     * @var string
     */
    protected $key;

    /**
     * Create a new SparkPost transport instance.
     *
     * @param  \GuzzleHttp\ClientInterface  $client
     * @param  string  $key
     * @return void
     */
    public function __construct(ClientInterface $client, $key)
    {
        $this->client = $client;
        $this->key = $key;
    }

    /**
     * {@inheritdoc}
     */
    public function send(Swift_Mime_Message $message, &$failedRecipients = null)
    {
        $this->beforeSendPerformed($message);

        $recipients = $this->getRecipients($message);

        $message->setBcc([]);

        $options = [
            'headers' => [
                'Authorization' => $this->key,
            ],
            'json' => [
                'recipients' => $recipients,
                'content' => [
                    'html' => $message->getBody(),
                    'from' => $this->getFrom($message),
                    'subject' => $message->getSubject(),
                ],
            ],
        ];

        return $this->client->post('https://api.sparkpost.com/api/v1/transmissions', $options);
    }

    /**
     * Get all the addresses this message should be sent to.
     *
     * Note that SparkPost still respects CC, BCC headers in raw message itself.
     *
     * @param  \Swift_Mime_Message $message
     * @return array
     */
    protected function getRecipients(Swift_Mime_Message $message)
    {
        $to = $bcc = [];

        if ($message->getTo()) {
            $to = array_merge($to, array_keys($message->getTo()));
        }

        if ($message->getCc()) {
            $to = array_merge($to, array_keys($message->getCc()));
        }

        if ($message->getBcc()) {
            $to = array_merge($bcc, array_keys($message->getBcc()));
        }

        $recipients = array_map(function ($address) {
            return ['address' => [ 'email' => $address ,'header_to' => $address]];
        }, $to);

        return $recipients;
    }

    /**
     * Get From in a format needed by SparkPost.
     *
     * @param Swift_Mime_Message $message
     * @return array
     */
    protected function getFrom(Swift_Mime_Message $message)
    {
        $from = array_map(function ($email, $name) {
            return [ 'name' => $name, 'email' => $email ];
        }, array_keys($message->getFrom()), $message->getFrom());

        return $from[0];
    }

    /**
     * Get the API key being used by the transport.
     *
     * @return string
     */
    public function getKey()
    {
        return $this->key;
    }<commit_msg>some style fixes I missed<commit_after><?php

namespace Illuminate\Mail\Transport;

use Swift_Mime_Message;
use GuzzleHttp\ClientInterface;

class SparkPostTransport extends Transport
{
    /**
     * Guzzle client instance.
     *
     * @var \GuzzleHttp\ClientInterface
     */
    protected $client;

    /**
     * The SparkPost API key.
     *
     * @var string
     */
    protected $key;

    /**
     * Create a new SparkPost transport instance.
     *
     * @param  \GuzzleHttp\ClientInterface  $client
     * @param  string  $key
     * @return void
     */
    public function __construct(ClientInterface $client, $key)
    {
        $this->client = $client;
        $this->key = $key;
    }

    /**
     * {@inheritdoc}
     */
    public function send(Swift_Mime_Message $message, &$failedRecipients = null)
    {
        $this->beforeSendPerformed($message);

        $recipients = $this->getRecipients($message);

        $message->setBcc([]);

        $options = [
            'headers' => [
                'Authorization' => $this->key,
            ],
            'json' => [
                'recipients' => $recipients,
                'content' => [
                    'html' => $message->getBody(),
                    'from' => $this->getFrom($message),
                    'subject' => $message->getSubject(),
                ],
            ],
        ];

        return $this->client->post('https://api.sparkpost.com/api/v1/transmissions', $options);
    }

    /**
     * Get all the addresses this message should be sent to.
     *
     * Note that SparkPost still respects CC, BCC headers in raw message itself.
     *
     * @param  \Swift_Mime_Message $message
     * @return array
     */
    protected function getRecipients(Swift_Mime_Message $message)
    {
        $to = $bcc = [];

        if ($message->getTo()) {
            $to = array_merge($to, array_keys($message->getTo()));
        }

        if ($message->getCc()) {
            $to = array_merge($to, array_keys($message->getCc()));
        }

        if ($message->getBcc()) {
            $to = array_merge($bcc, array_keys($message->getBcc()));
        }

        $recipients = array_map(function ($address) {
            return ['address' => ['email' => $address, 'header_to' => $address]];
        }, $to);

        return $recipients;
    }

    /**
     * Get From in a format needed by SparkPost.
     *
     * @param Swift_Mime_Message $message
     * @return array
     */
    protected function getFrom(Swift_Mime_Message $message)
    {
        $from = array_map(function ($email, $name) {
            return ['name' => $name, 'email' => $email];
        }, array_keys($message->getFrom()), $message->getFrom());

        return $from[0];
    }

    /**
     * Get the API key being used by the transport.
     *
     * @return string
     */
    public function getKey()
    {
        return $this->key;
    }
{'fraction_non_alphanumeric': 0.14440061738981308, 'fraction_numerical': 0.0006859886811867604, 'mean_word_length': 1.84765625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, 'https://': 2, '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': '4622124', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1691, 'n_words': 370}