<commit_before><?php

namespace Synapse\Email;

use Synapse\Email\Entity\Email;
use Synapse\Email\Mapper\Email as EmailMapper;
use Mandrill;

/**
 * Service to send emails
 */
class MandrillSender implements SenderInterface
{
    /**
     * @var Mandrill
     */
    protected $mandrill;

    /**
     * @var Synapse\Mapper\Email
     */
    protected $mapper;

    /**
     * @param Mandrill             $mandrill
     * @param Synapse\Mapper\Email $mapper
     */
    public function __construct(Mandrill $mandrill, EmailMapper $mapper)
    {
        $this->mandrill = $mandrill;
        $this->mapper   = $mapper;
    }

    /**
     * {@inheritDoc}
     */
    public function send(Email $email)
    {
        $time = time();

        $message = $this->buildMessage($email);

        $result = $this->mandrill->messages->send($message);
        $result = array_shift($result);

        $email->setStatus($result['status']);
        $email->setSent($time);
        $email->setUpdated($time);

        $this->mapper->update($email);

        return [$email, $result];
    }

    /**
     * Build Mandrill compatible message array from email entity
     *
     * Documentation at https://mandrillapp.com/api/docs/messages.php.html
     *
     * @param  Email  $emails
     * @return array
     */
    protected function buildMessage(Email $email)
    {
        // Create attachments array
        $attachments = json_decode($email->getAttachments(), true);<commit_msg>Refs #70 - Use correct class name.<commit_after><?php

namespace Synapse\Email;

use Mandrill;

/**
 * Service to send emails
 */
class MandrillSender implements SenderInterface
{
    /**
     * @var Mandrill
     */
    protected $mandrill;

    /**
     * @var EmailMapper
     */
    protected $mapper;

    /**
     * @param Mandrill    $mandrill
     * @param EmailMapper $mapper
     */
    public function __construct(Mandrill $mandrill, EmailMapper $mapper)
    {
        $this->mandrill = $mandrill;
        $this->mapper   = $mapper;
    }

    /**
     * {@inheritDoc}
     */
    public function send(EmailEntity $email)
    {
        $time = time();

        $message = $this->buildMessage($email);

        $result = $this->mandrill->messages->send($message);
        $result = array_shift($result);

        $email->setStatus($result['status']);
        $email->setSent($time);
        $email->setUpdated($time);

        $this->mapper->update($email);

        return [$email, $result];
    }

    /**
     * Build Mandrill compatible message array from email entity
     *
     * Documentation at https://mandrillapp.com/api/docs/messages.php.html
     *
     * @param  EmailEntity  $emails
     * @return array
     */
    protected function buildMessage(EmailEntity $email)
    {
        // Create attachments array
        $attachments = json_decode($email->getAttachments(), true);
{'fraction_non_alphanumeric': 0.13758272378962033, 'fraction_numerical': 0.0006966213862765587, 'mean_word_length': 2.28604118993135, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '6327989', 'n_tokens_mistral': 886, 'n_tokens_neox': 838, 'n_words': 176}