Mail   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 54
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A config() 0 12 1
A send() 0 11 3
A add() 0 8 1
A getResult() 0 3 1
1
<?php
2
3
4
namespace coffeebreaks;
5
6
7
use PHPMailer\PHPMailer\Exception;
8
use PHPMailer\PHPMailer\PHPMailer;
9
use PHPMailer\PHPMailer\SMTP;
10
11
class Mail
12
{
13
14
    private $mail;
15
    private $result;
16
17
18
    public function config(string $host, string $user, string $pass, int $port)
19
    {
20
        $this->mail = new PHPMailer(1);
21
        $this->mail->isSMTP();
22
        $this->mail->Host = $host;
23
        $this->mail->SMTPAuth = true;
24
        $this->mail->Username = $user;
25
        $this->mail->Password = $pass;
26
        $this->mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
27
        $this->mail->Port = $port;
28
29
        $this->mail->isHTML(true);
30
31
    }
32
33
    public function add(string $fromAdress, string $fromName, string $mailTo, string $subject, string $body)
34
    {
35
        $this->mail->setLanguage('br');
36
        $this->mail->setFrom($fromAdress, $fromName);
37
        $this->mail->addAddress($mailTo);
38
        $this->mail->Subject = $subject;
39
        $this->mail->Body = $body;
40
        return $this->send();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->send() targeting coffeebreaks\Mail::send() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
41
42
43
    }
44
45
    /**
46
     * @return mixed
47
     */
48
    public function getResult()
49
    {
50
        return $this->result;
51
    }
52
53
54
    private function send()
55
    {
56
        try {
57
            if ($this->mail->send()){
58
                $this->result = true;
59
60
            }else{
61
                $this->result = false;
62
            }
63
        } catch (Exception $e){
64
            echo "Error email send:: ". $e->errorMessage();
65
        }
66
    }
67
68
}