NewsletterServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 8 1
A register() 0 19 3
1
<?php
2
3
namespace Spatie\Newsletter;
4
5
use DrewM\MailChimp\MailChimp;
6
use Illuminate\Support\ServiceProvider;
7
8
class NewsletterServiceProvider extends ServiceProvider
9
{
10
    protected $defer = false;
11
12
    public function boot()
13
    {
14
        $this->mergeConfigFrom(__DIR__.'/../config/newsletter.php', 'newsletter');
15
16
        $this->publishes([
17
            __DIR__.'/../config/newsletter.php' => config_path('newsletter.php'),
18
        ]);
19
    }
20
21
    public function register()
22
    {
23
        $this->app->singleton(Newsletter::class, function () {
24
            $driver = config('newsletter.driver', 'api');
25
            if (is_null($driver) || $driver === 'log') {
26
                return new NullDriver($driver === 'log');
27
            }
28
29
            $mailChimp = new Mailchimp(config('newsletter.apiKey'));
30
31
            $mailChimp->verify_ssl = config('newsletter.ssl', true);
32
33
            $configuredLists = NewsletterListCollection::createFromConfig(config('newsletter'));
34
35
            return new Newsletter($mailChimp, $configuredLists);
36
        });
37
38
        $this->app->alias(Newsletter::class, 'newsletter');
39
    }
40
}
41