BigQueryServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 14 1
A boot() 0 6 1
A guardAgainstInvalidConfiguration() 0 6 3
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
37
            return BigQueryClientFactory::createForConfig($bigQueryConfig);
38
        });
39
40
        $this->app->alias(BigQueryClient::class, 'bigquery');
41
    }
42
43
    protected function guardAgainstInvalidConfiguration(array $bigQueryConfig = null)
44
    {
45
        if (! file_exists($bigQueryConfig['application_credentials']) && ! array_key_exists('keyFile', $bigQueryConfig)) {
46
            throw InvalidConfiguration::credentialsJsonDoesNotExist($bigQueryConfig['application_credentials']);
47
        }
48
    }
49
}
50