guardAgainstInvalidConfiguration()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace SchulzeFelix\AdWords;
4
5
use Illuminate\Support\ServiceProvider;
6
use SchulzeFelix\AdWords\Commands\GenerateRefreshTokenCommand;
7
use SchulzeFelix\AdWords\Exceptions\InvalidConfiguration;
8
9
class AdWordsServiceProvider 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/adwords-targeting-idea-service.php' => config_path('adwords-targeting-idea-service.php'),
20
        ]);
21
    }
22
23
    /**
24
     * Register the service provider.
25
     */
26
    public function register()
27
    {
28
        $this->mergeConfigFrom(__DIR__.'/config/adwords-targeting-idea-service.php', 'adwords-targeting-idea-service');
29
30
        $adwordsConfig = config('adwords-targeting-idea-service');
31
32
        $this->app->bind('command.adwords:token', GenerateRefreshTokenCommand::class);
33
        $this->commands([
34
            'command.adwords:token',
35
        ]);
36
37
        $this->app->bind(AdWordsService::class, function () use ($adwordsConfig) {
38
            return AdWordsServiceFactory::createForConfig($adwordsConfig);
39
        });
40
41
        $this->app->bind(AdWords::class, function () use ($adwordsConfig) {
42
            $this->guardAgainstInvalidConfiguration($adwordsConfig);
43
44
            $adWordsService = app(AdWordsService::class);
45
46
            return new AdWords($adWordsService);
47
        });
48
49
        $this->app->alias(AdWords::class, 'laravel-adwords-targeting-idea-service');
50
    }
51
52
    protected function guardAgainstInvalidConfiguration(array $adwordsConfig = null)
53
    {
54
        if (empty($adwordsConfig['developer_token'])) {
55
            throw InvalidConfiguration::developerTokenNotSpecified();
56
        }
57
    }
58
}
59