Passed
Push — develop ( c3bbc8...62f833 )
by Septianata
15:27
created

GoogleDriveServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 16.66%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 12
c 1
b 0
f 0
dl 0
loc 28
ccs 2
cts 12
cp 0.1666
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A boot() 0 21 2
1
<?php
2
3
namespace App\Providers;
4
5
use Google\Service\Drive;
6
use Google_Client;
7
use Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter;
8
use Illuminate\Support\Facades\Storage;
9
use Illuminate\Support\ServiceProvider;
10
use League\Flysystem\Filesystem;
11
12
class GoogleDriveServiceProvider extends ServiceProvider
13
{
14
    /**
15
     * Bootstrap the application services.
16
     *
17
     * @return void
18
     */
19 73
    public function boot()
20
    {
21 73
        Storage::extend('google', function ($app, $config) {
22
            $client = new Google_Client;
23
24
            $client->setClientId($config['clientId']);
25
            $client->setClientSecret($config['clientSecret']);
26
            $client->refreshToken($config['refreshToken']);
27
28
            /** @var \Google\Service\Drive|\Google_Service_Drive $service */
29
            $service = new Drive($client);
30
31
            $options = [];
32
33
            if (isset($config['teamDriveId'])) {
34
                $options['teamDriveId'] = $config['teamDriveId'];
35
            }
36
37
            $adapter = new GoogleDriveAdapter($service, $config['folderId'], $options);
38
39
            return new Filesystem($adapter);
40 73
        });
41 73
    }
42
}
43