Completed
Push — master ( 21b36f...33e787 )
by Mahmoud
03:36
created

MailsAbstract::setEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace App\Port\Email\Abstracts;
4
5
use Illuminate\Support\Facades\Config;
6
use Illuminate\Support\Facades\Mail;
7
8
/**
9
 * Class MailsAbstract.
10
 *
11
 * @author Mahmoud Zalt <[email protected]>
12
 */
13
abstract class MailsAbstract
14
{
15
16
    /**
17
     * @var string
18
     */
19
    public $fromEmail;
20
21
    /**
22
     * @var string
23
     */
24
    public $fromName;
25
26
    /**
27
     * @var string
28
     */
29
    protected $toEmail;
30
31
    /**
32
     * @var string
33
     */
34
    protected $toName;
35
36
    /**
37
     * @var string
38
     */
39
    protected $subject;
40
41
    /**
42
     * MailsAbstract constructor.
43
     *
44
     * @param \Illuminate\Mail\Mailer $mail
0 ignored issues
show
Bug introduced by
There is no parameter named $mail. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
45
     */
46
    public function __construct()
47
    {
48
        // set default values from the config for both emails directions
49
        // you can override everything later when using it.
50
        $this->from(config('mail.from.address'), config('mail.from.name'));
51
        $this->to(config('mail.to.address'), config('mail.to.name'));
52
    }
53
54
    /**
55
     * Send the email
56
     *
57
     * @param array $data
58
     *
59
     * @return  bool
60
     */
61
    public function send($data = [])
62
    {
63
        // TODO: surround with try and catch block and return exception
64
65
        // check if sending emails is enabled and if this is not running a testing environment
66
        if (Config::get('mail.enabled')) {
67
            Mail::queue('EmailTemplates.' . $this->template, $data, function ($m) {
0 ignored issues
show
Bug introduced by
The property template does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
68
                $m->from($this->fromEmail, $this->fromName);
69
                $m->to($this->toEmail, $this->toName)
70
                    ->subject($this->subject);
71
            });
72
        }
73
74
        return true;
75
    }
76
77
    /**
78
     * @param $subject
79
     */
80
    public function setSubject($subject)
81
    {
82
        $this->subject = $subject;
83
    }
84
85
    /**
86
     * @param        $email
87
     * @param string $name
88
     *
89
     * @return  $this
90
     */
91
    public function to($email, $name = '')
92
    {
93
        $this->toEmail = $email;
94
        $this->toName = $name;
95
96
        return $this;
97
    }
98
99
    /**
100
     * @param        $email
101
     * @param string $name
102
     *
103
     * @return  $this
104
     */
105
    public function from($email, $name = '')
106
    {
107
        $this->fromEmail = $email;
108
        $this->fromName = $name;
109
110
        return $this;
111
    }
112
113
}
114