<commit_before><?php

namespace Athens\SendGrid\Emailer;

use UWDOEM\Framework\Emailer\AbstractEmailer;
use UWDOEM\Framework\Email\EmailInterface;

use SendGrid;
use SendGrid\Email as SendGridEmail;


/**
 * Class Emailer
 *
 * @package Athens\SendGrid\Emailer
 */
class Emailer extends AbstractEmailer
{

    /** @var SendGrid */
    protected static $sendgrid;

    /**
     * @return SendGrid
     * @throws \Exception If SENDGRID_API_KEY has not been declared.
     */
    protected function getSendGrid() {
        if (static::$sendgrid === null) {
            if (defined('SENDGRID_API_KEY') === false) {
                throw new \Exception("You must define a constant SENDGRID_API_KEY before using this library.");
            }

            static::$sendgrid = new SendGrid(SENDGRID_API_KEY);
        }

        return static::$sendgrid;
    }

    /**
     * @param EmailInterface $email
     * @return string
     */
    protected function buildHeaders(EmailInterface $email)
    {
        $headers = ["From: " . $email->getFrom(), ];

        if ($email->getMimeVersion() !== null) {
            $headers[] = "MIME-VERSION: " . $email->getMimeVersion();
        }

        if ($email->getContentType() !== null) {
            $headers[] = "Content-type: " . $email->getContentType();
        }

        if ($email->getCc() !== null) {
            $headers[] = "Cc: " . $email->getCc();
        }

        if ($email->getBcc() !== null) {
            $headers[] = "Bcc: " . $email->getBcc();
        }

        if ($email->getXMailer() !== null) {
            $headers[] = "X-Mailer: " . $email->getXMailer();
        }

        return implode("\r\n", $headers);
    }

    /**
     * @param string         $body
     * @param EmailInterface $email
     * @return boolean
     */
    protected function doSend($body, EmailInterface $email)
    {
        $sendgridEmail = new SendGridEmail();

        $sendgridEmail
            ->addTo($email->getTo())
            ->setSubject($email->getSubject())
            ->addCc($email->getCc())
            ->setBcc($email->getBcc())
            ->setHtml($body);

        $res = static::getSendGrid()->send($sendgridEmail);

        return $res->getCode === 200;
    }
}
<commit_msg>Remove vestigial header creation code.<commit_after><?php

namespace Athens\SendGrid;

use UWDOEM\Framework\Emailer\AbstractEmailer;
use UWDOEM\Framework\Email\EmailInterface;

use SendGrid;
use SendGrid\Response;
use SendGrid\Email as SendGridEmail;

/**
 * Class Emailer
 *
 * @package Athens\SendGrid\Emailer
 */
class Emailer extends AbstractEmailer
{

    /** @var SendGrid */
    protected static $sendgrid;

    /**
     * @return SendGrid
     * @throws \Exception If SENDGRID_API_KEY has not been declared.
     */
    protected function getSendGrid()
    {
        if (static::$sendgrid === null) {
            if (defined('SENDGRID_API_KEY') === false) {
                throw new \Exception("You must define a constant SENDGRID_API_KEY before using this library.");
            }

            static::$sendgrid = new SendGrid(SENDGRID_API_KEY);
        }

        return static::$sendgrid;
    }

    /**
     * @param string         $body
     * @param EmailInterface $email
     * @return boolean
     */
    protected function doSend($body, EmailInterface $email)
    {

        /** @var SendGridEmail $sendgridEmail */
        $sendgridEmail = new SendGridEmail();

        $sendgridEmail
            ->addTo($email->getTo())
            ->setSubject($email->getSubject())
            ->addCc($email->getCc())
            ->setBcc($email->getBcc())
            ->setHtml($body);

        /** @var Response $res */
        $res = static::getSendGrid()->send($sendgridEmail);

        return $res->getCode() === 200;
    }
}

{'fraction_non_alphanumeric': 0.1461864406779661, 'fraction_numerical': 0.0015889830508474577, 'mean_word_length': 2.1927303465765005, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, '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': '1252180', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1117, 'n_words': 235}