Completed
Push — master ( 1758f1...601966 )
by Felix
08:03
created

SearchConsoleServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace SchulzeFelix\SearchConsole;
4
5
use Illuminate\Support\ServiceProvider;
6
use SchulzeFelix\SearchConsole\Exceptions\InvalidConfiguration;
7
8
class SearchConsoleServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Perform post-registration booting of services.
12
     *
13
     * @return void
14
     */
15
    public function boot()
16
    {
17
        $this->publishes([
18
            __DIR__.'/config/search-console.php' => config_path('search-console.php'),
19
        ]);
20
    }
21
22
    /**
23
     * Register any package services.
24
     *
25
     * @return void
26
     */
27
    public function register()
28
    {
29
        $this->mergeConfigFrom(__DIR__.'/config/search-console.php', 'search-console');
30
31
        $searchConsoleConfig = config('search-console');
32
33
        $this->app->bind(SearchConsoleClient::class, function () use ($searchConsoleConfig) {
34
            return SearchConsoleClientFactory::createForConfig($searchConsoleConfig);
35
        });
36
37
        $this->app->bind(SearchConsole::class, function () use ($searchConsoleConfig) {
38
            $this->guardAgainstInvalidConfiguration($searchConsoleConfig);
39
40
            $client = app(SearchConsoleClient::class);
41
42
            return new SearchConsole($client);
43
        });
44
45
        $this->app->alias(SearchConsole::class, 'laravel-searchconsole');
46
47
    }
48
49
    protected function guardAgainstInvalidConfiguration(array $searchConsoleConfig = null)
50
    {
51 View Code Duplication
        if ($searchConsoleConfig['auth_type'] == 'service_account' && ! file_exists($searchConsoleConfig['connections']['service_account']['application_credentials'])) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
            throw InvalidConfiguration::credentialsJsonDoesNotExist($searchConsoleConfig['connections']['service_account']['application_credentials']);
53
        }
54
55 View Code Duplication
        if ($searchConsoleConfig['auth_type'] == 'oauth_json' && ! file_exists($searchConsoleConfig['connections']['oauth_json']['auth_config'])) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
            throw InvalidConfiguration::credentialsJsonDoesNotExist($searchConsoleConfig['connections']['oauth_json']['auth_config']);
57
        }
58
59
    }
60
61
}