Completed
Push — master ( c4a284...c64a87 )
by Freek
07:27 queued 05:53
created

GoogleCalendarServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 35
rs 10
c 2
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A register() 0 14 1
A guardAgainstInvalidConfiguration() 0 10 3
1
<?php
2
3
namespace Spatie\GoogleCalendar;
4
5
use Illuminate\Support\ServiceProvider;
6
use Spatie\GoogleCalendar\Exceptions\InvalidConfiguration;
7
8
class GoogleCalendarServiceProvider extends ServiceProvider
9
{
10
    public function boot()
11
    {
12
        $this->publishes([
13
            __DIR__.'/../config/google-calendar.php' => config_path('google-calendar.php'),
14
        ], 'config');
15
    }
16
17
    public function register()
18
    {
19
        $this->mergeConfigFrom(__DIR__.'/../config/google-calendar.php', 'google-calendar');
20
21
        $this->app->bind(GoogleCalendar::class, function () {
22
            $config = config('laravel-google-calendar');
23
24
            $this->guardAgainstInvalidConfiguration($config);
25
26
            return GoogleCalendarFactory::createForCalendarId($config['calendar_id']);
27
        });
28
29
        $this->app->alias(GoogleCalendar::class, 'laravel-google-calendar');
30
    }
31
32
    protected function guardAgainstInvalidConfiguration(array $config = null)
33
    {
34
        if (empty($config['calendar_id'])) {
35
            throw InvalidConfiguration::calendarIdNotSpecified();
36
        }
37
38
        if (! file_exists($config['service_account_credentials_json'])) {
39
            throw InvalidConfiguration::credentialsJsonDoesNotExist($config['service_account_credentials_json']);
40
        }
41
    }
42
}
43