Issues (31)

src/Traits/MailableTrait.php (5 issues)

1
<?php
2
3
namespace Nip\Mail\Traits;
4
5
use Nip\Mail\Message;
6
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
7
use Symfony\Component\Mailer\Mailer;
8
9
/**
10
 * Class MailableTrait.
11
 */
12
trait MailableTrait
13
{
14
    use MailerAwareTrait;
15
16
    /**
17
     * @return void
18
     */
19
    public function send()
20
    {
21
        $mailer = $this->getMailer();
22
        $message = $this->buildMailMessage();
23
24
        $this->beforeSend($mailer, $message);
25
        try {
26
            $mailer->send($message);
27
            $this->afterSend($mailer, $message);
28
        } catch (TransportExceptionInterface $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
29
        }
30
    }
31
32
    /**
33
     * @return Message
34
     */
35
    public function buildMailMessage()
36
    {
37
        $message = $this->newMailMessage();
38
        $this->buildMailMessageFrom($message);
39
        $this->buildMailMessageRecipients($message);
40
        $this->buildMailMessageSubject($message);
41
        $this->buildMailMessageBody($message);
42
        $this->buildMailMessageAttachments($message);
43
        $this->buildMailMessageMergeTags($message);
44
        $this->buildMailMessageCustomArgs($message);
45
46
        return $message;
47
    }
48
49
    /**
50
     * @return Message
51 1
     */
52
    public function newMailMessage()
53 1
    {
54
        $message = new Message();
55 1
56
        return $message;
57
    }
58
59
    /**
60
     * @param Mailer $mailer
61
     * @param Message $message
62
     */
63
    protected function beforeSend($mailer, $message)
0 ignored issues
show
The parameter $mailer is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

63
    protected function beforeSend(/** @scrutinizer ignore-unused */ $mailer, $message)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $message is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

63
    protected function beforeSend($mailer, /** @scrutinizer ignore-unused */ $message)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
    {
65
    }
66
67
    /**
68
     * @param Mailer $mailer
69
     * @param Message $message
70
     * @param int $recipients
71
     */
72
    protected function afterSend($mailer, $message)
0 ignored issues
show
The parameter $message is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

72
    protected function afterSend($mailer, /** @scrutinizer ignore-unused */ $message)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $mailer is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

72
    protected function afterSend(/** @scrutinizer ignore-unused */ $mailer, $message)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
73
    {
74
    }
75
76
    /**
77
     * @param Message $message
78
     */
79
    abstract public function buildMailMessageFrom(&$message);
80
81
    /**
82
     * @param Message $message
83
     */
84
    abstract public function buildMailMessageRecipients(&$message);
85
86
    /**
87
     * @param Message $message
88
     */
89
    abstract public function buildMailMessageSubject(&$message);
90
91
    /**
92
     * @param Message $message
93
     */
94
    abstract public function buildMailMessageBody(&$message);
95
96
    /**
97
     * @param Message $message
98
     */
99
    abstract public function buildMailMessageAttachments(&$message);
100
101
    /**
102
     * @param Message $message
103
     */
104
    abstract public function buildMailMessageMergeTags(&$message);
105
106
    /**
107
     * @param Message $message
108
     */
109
    abstract public function buildMailMessageCustomArgs(&$message);
110
}
111