SyncMailchimpMember   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A handle() 9 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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