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

SearchConsoleServiceProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 11.11 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 6
loc 54
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A register() 0 21 1
B guardAgainstInvalidConfiguration() 6 11 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}