Completed
Push — master ( 34e88f...34ef7e )
by Felix
04:02
created

BigQueryServiceProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 14 1
A guardAgainstInvalidConfiguration() 0 6 2
A boot() 0 4 1
A setupConfig() 0 12 3
1
<?php
2
3
namespace SchulzeFelix\BigQuery;
4
5
use Illuminate\Support\ServiceProvider;
6
use Google\Cloud\BigQuery\BigQueryClient;
7
use Laravel\Lumen\Application as LumenApplication;
8
use Illuminate\Foundation\Application as LaravelApplication;
9
use SchulzeFelix\BigQuery\Exceptions\InvalidConfiguration;
10
11
class BigQueryServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Perform post-registration booting of services.
15
     *
16
     * @return void
17
     */
18
    public function boot()
19
    {
20
        $this->setupConfig();
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'])) {
46
            throw InvalidConfiguration::credentialsJsonDoesNotExist($bigQueryConfig['application_credentials']);
47
        }
48
    }
49
50
    protected function setupConfig()
51
    {
52
        $source = realpath(__DIR__.'/config/bigquery.php');
53
54
        if ($this->app instanceof LaravelApplication) {
55
            $this->publishes([$source => config_path('bigquery.php')]);
56
        } elseif ($this->app instanceof LumenApplication) {
0 ignored issues
show
Bug introduced by
The class Laravel\Lumen\Application does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
57
            $this->app->configure('bigquery');
58
        }
59
60
        $this->mergeConfigFrom($source, 'bigquery');
61
    }
62
}
63