Completed
Push — master ( 7696c0...144c46 )
by Felix
04:21
created

BigQueryServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
1
<?php
2
3
namespace SchulzeFelix\BigQuery;
4
5
use Google\Cloud\BigQuery\BigQueryClient;
6
use Illuminate\Support\ServiceProvider;
7
use SchulzeFelix\BigQuery\Exceptions\InvalidConfiguration;
8
9
class BigQueryServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Perform post-registration booting of services.
13
     *
14
     * @return void
15
     */
16
    public function boot()
17
    {
18
        $this->publishes([
19
            __DIR__.'/config/bigquery.php' => config_path('bigquery.php'),
20
        ]);
21
    }
22
23
    /**
24
     * Register any package services.
25
     *
26
     * @return void
27
     */
28
    public function register()
29
    {
30
        $this->mergeConfigFrom(__DIR__.'/config/bigquery.php', 'bigquery');
31
32
        $bigQueryConfig = config('bigquery');
33
34
        $this->app->bind(BigQueryClient::class, function () use ($bigQueryConfig) {
35
            $this->guardAgainstInvalidConfiguration($bigQueryConfig);
36
            return BigQueryClientFactory::createForConfig($bigQueryConfig);
37
        });
38
39
        $this->app->alias(BigQueryClient::class, 'bigquery');
40
41
    }
42
43
    protected function guardAgainstInvalidConfiguration(array $bigQueryConfig = null)
44
    {
45
        if (! file_exists($bigQueryConfig['application_credentials'])) {
46
            throw InvalidConfiguration::credentialsJsonDoesNotExist($bigQueryConfig['application_credentials']);
47
        }
48
49
    }
50
51
}
52