Passed
Pull Request — master (#50)
by Ronan
09:06
created

UserMailJob   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 14
c 1
b 0
f 0
dl 0
loc 50
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 8 2
A __construct() 0 4 1
1
<?php
2
3
namespace App\Queue;
4
5
use App\Facades\Mail;
6
use App\Model\User;
7
use Ronanchilvers\Foundation\Queue\Exception\FailedJobException;
8
use Ronanchilvers\Foundation\Queue\Job\Job;
9
10
/**
11
 * Base job for sending user emails
12
 *
13
 * @author Ronan Chilvers <[email protected]>
14
 */
15
abstract class UserMailJob extends Job
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $queue = 'emails';
21
22
    /**
23
     * @var string
24
     */
25
    protected $emailClass = null;
26
27
    /**
28
     * @var App\Model\User
0 ignored issues
show
Bug introduced by
The type App\Queue\App\Model\User was not found. Did you mean App\Model\User? If so, make sure to prefix the type with \.
Loading history...
29
     */
30
    protected $user;
31
32
    /**
33
     * @var array
34
     */
35
    protected $internalProperties = [
36
        'delay',
37
        'queue',
38
        'emailClass'
39
    ];
40
41
    /**
42
     * Class constructor
43
     *
44
     * @author Ronan Chilvers <[email protected]>
45
     */
46
    public function __construct(
47
        User $user,
48
    ) {
49
        $this->user = $user;
0 ignored issues
show
Documentation Bug introduced by
It seems like $user of type App\Model\User is incompatible with the declared type App\Queue\App\Model\User of property $user.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     *
55
     * @author Ronan Chilvers <[email protected]>
56
     */
57
    public function execute()
58
    {
59
        $class = $this->emailClass;
60
        $mail = new $class(
61
            $this->user
62
        );
63
        if (!Mail::send($mail)) {
0 ignored issues
show
Bug introduced by
The method send() does not exist on App\Facades\Mail. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

63
        if (!Mail::/** @scrutinizer ignore-call */ send($mail)) {
Loading history...
64
            throw new FailedJobException('Unable to send User email : ' . $class);
65
        }
66
    }
67
}
68