Completed
Push — 0.4 ( e232e8...87763b )
by Diego
05:27
created

UpdateMailchimpMemberEmail   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 42
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 9 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.apikey'))) {
51 1
            $manager = App::make(MailchimpManager::class);
52 1
            $manager->updateMembersEmail($this->member, $this->oldEmail);
53 1
        }        
54 1
    }
55
}
56