Passed
Push — master ( 588c31...9953d3 )
by Stephen
02:33
created

SendMailJob::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 3
1
<?php
2
3
namespace Sfneal\PostOffice\MailCenter;
4
5
use Illuminate\Mail\Mailable;
6
use Sfneal\Queueables\AbstractJob;
7
8
// TODO: create package SendMail?
9
class SendMailJob extends AbstractJob
10
{
11
    /**
12
     * @var string Queue to use
13
     */
14
    public $queue = 'mail';
15
16
    /**
17
     * @var string Queue connection to use
18
     */
19
    public $connection = 'database';
20
21
    /**
22
     * @var string Email address of recipient
23
     */
24
    public $to;
25
26
    /**
27
     * @var string Email address of users to CC
28
     */
29
    public $cc;
30
31
    /**
32
     * @var Mailable The mailable to send to the recipient
33
     */
34
    public $mailable;
35
36
    /**
37
     * Create a new job instance.
38
     *
39
     * @param string $to
40
     * @param Mailable $mailable
41
     * @param array|null $cc
42
     */
43
    public function __construct(string $to, Mailable $mailable, array $cc = null)
44
    {
45
        $this->to = $to;
46
        $this->mailable = $mailable;
47
        $this->cc = $cc;
0 ignored issues
show
Documentation Bug introduced by
It seems like $cc can also be of type array. However, the property $cc is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
48
    }
49
50
    /**
51
     * Execute the job.
52
     *
53
     * @return void
54
     */
55
    public function handle()
56
    {
57
        if (!SendMailAction::execute($this->mailable, $this->to, $this->cc)) {
0 ignored issues
show
Bug introduced by
$this->cc of type string is incompatible with the type array|null expected by parameter $cc of Sfneal\PostOffice\MailCe...ndMailAction::execute(). ( Ignorable by Annotation )

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

57
        if (!SendMailAction::execute($this->mailable, $this->to, /** @scrutinizer ignore-type */ $this->cc)) {
Loading history...
58
            $this->fail();
59
        }
60
    }
61
}
62