UpdateMailchimpMemberEmail::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php namespace DiegoCaprioli\Larachimp\Jobs;
2
3
use DiegoCaprioli\Larachimp\Models\LarachimpListMember;
4
use DiegoCaprioli\Larachimp\Services\MailchimpManager;
5
use Illuminate\Contracts\Bus\SelfHandling;
6
use Illuminate\Contracts\Queue\ShouldQueue;
7
use Illuminate\Queue\InteractsWithQueue;
8
use Illuminate\Queue\SerializesModels;
9
use Illuminate\Support\Facades\App;
10
11
/**
12
 * Updates the user's email in the Mailchimp list
13
 */
14
class UpdateMailchimpMemberEmail implements SelfHandling, ShouldQueue
15
{
16
    use InteractsWithQueue, SerializesModels;
17
18
    /**
19
     * An instance object that can be synced as a Mailchimp List member.
20
     *
21
     * @var \DiegoCaprioli\Larachimp\Models\LarachimpListMember
22
     */
23
    private $member;
24
25
    /**
26
     * The old email that needs to be replaced with the new one on the member
27
     * 
28
     * @var string
29
     */
30
    private $oldEmail;
31
32
    /**
33
     * Create a new job instance.
34
     * 
35
     * @param \DiegoCaprioli\Larachimp\Models\LarachimpListMember $member
36
     */
37 1
    public function __construct(LarachimpListMember $member, $oldEmail)
38
    {
39 1
        $this->member = $member;
40 1
        $this->oldEmail = $oldEmail;
41 1
    }
42
43
    /**
44
     * Execute the job.
45
     */
46 1
    public function handle()
47
    {
48
        // The Job only executes if the apiKey is set! This works sort of an
49
        // on/off switch
50 1
        if (!empty(config('diegocaprioli.larachimp.larachimp.api_key'))) {
51 1
            $manager = App::make(MailchimpManager::class);
52 1
            $manager->updateMembersEmail($this->member, $this->oldEmail);
53 1
        }        
54 1
    }
55
}
56