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

GoogleCalendarFactory::createCalendarClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Spatie\GoogleCalendar;
4
5
use Google_Client;
6
use Google_Service_Calendar;
7
8
class GoogleCalendarFactory
9
{
10
    public static function createForCalendarId(string $calendarId): GoogleCalendar
11
    {
12
        $config = config('laravel-google-calendar');
13
14
        $client = self::createAuthenticatedGoogleClient($config);
15
16
        $service = new Google_Service_Calendar($client);
17
18
        return self::createCalendarClient($service, $calendarId);
19
    }
20
21
    public static function createAuthenticatedGoogleClient(array $config): Google_Client
22
    {
23
        $client = new Google_Client;
24
25
        $client->setScopes([
26
            Google_Service_Calendar::CALENDAR,
27
        ]);
28
29
        $client->setAuthConfig($config['service_account_credentials_json']);
30
31
        return $client;
32
    }
33
34
    protected static function createCalendarClient(Google_Service_Calendar $service, string $calendarId): GoogleCalendar
35
    {
36
        return new GoogleCalendar($service, $calendarId);
37
    }
38
}
39