SyncMailchimpMember::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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
 * Syncronizes a user's email in the configured Mailchimp list. If the user's 
13
 * email does not exist yet on the list, it creates it. If it exists already, 
14
 * it syncs up the subscribers status (Subscribed / Unsubscribed)
15
 */
16 View Code Duplication
class SyncMailchimpMember implements SelfHandling, ShouldQueue
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    use InteractsWithQueue, SerializesModels;
19
20
    /**
21
     * An instance object that can be synced as a Mailchimp List member.
22
     *
23
     * @var \DiegoCaprioli\Larachimp\Models\LarachimpListMember
24
     */
25
    private $member;
26
27
    /**
28
     * Create a new job instance.
29
     * 
30
     * @param \DiegoCaprioli\Larachimp\Models\LarachimpListMember $member
31
     */
32 2
    public function __construct(LarachimpListMember $member)
33
    {
34 2
        $this->member = $member;
35 2
    }
36
37
    /**
38
     * Execute the job.
39
     */
40 2
    public function handle()
41
    {
42
        // The Job only executes if the apiKey is set! This works sort of an
43
        // on/off switch
44 2
        if (!empty(config('diegocaprioli.larachimp.larachimp.api_key'))) {
45 2
            $manager = App::make(MailchimpManager::class);
46 2
            $manager->syncMember($this->member);
47 2
        }        
48 2
    }
49
}
50