Passed
Push — master ( b114f1...5995d2 )
by Greg
01:59
created

MailSmtp::send()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 38
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 23
nc 3
nop 8
dl 0
loc 38
rs 9.552
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
namespace GJClasses;
3
4
class MailSmtp
5
{
6
    public function send($from_name, $from_address, $reply_name, $reply_address, $recipients, $subject, $message_html, $message_text)
7
    {
8
        $mail = new \PHPMailer();
9
10
        // $mail->SMTPDebug = 3;
11
        $mail->isSMTP();
12
        $mail->isHTML(true);
13
        $mail->CharSet = EMAIL_ENCODING_TYPE;
14
        $mail->SMTPSecure = SMTP_PROTOCOL;
15
        $mail->Host = SMTP_MAIL_SERVER;
16
        $mail->Port = SMTP_PORT;
17
        $mail->SMTPAuth = SMTP_AUTHENTICATION_ON;
18
        $mail->Username = SMTP_USERNAME;
19
        $mail->Password = SMTP_PASSWORD;
20
        $mail->setFrom($from_address, $from_name);
21
        $mail->addReplyTo($reply_address, $reply_name);
22
23
        foreach ($recipients AS $recipient) {
24
25
            $mail->Subject = $subject;
26
            $mail->Body = $message_html;
27
            $mail->AltBody = $message_text;
28
            $mail->clearAddresses();
29
            $mail->addAddress($recipient);
30
31
            if ($mail->send()) {
32
33
                $result_message = 'Email Send Succeeded';
34
35
            } else {
36
37
                $result_message = 'Email Send Failed';
38
39
            }
40
41
        }
42
43
        return $result_message;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $result_message seems to be defined by a foreach iteration on line 23. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
44
45
    }
46
}
47