Completed
Push — master ( 388ae8...d9e930 )
by Felix
09:31
created

AdWordsServiceProvider::register()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 0
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
    /**
25
     * Register the service provider.
26
     */
27
    public function register()
28
    {
29
        $this->mergeConfigFrom(__DIR__.'/config/adwords-targeting-idea-service.php', 'adwords-targeting-idea-service');
30
31
        $adwordsConfig = config('adwords-targeting-idea-service');
32
33
        $this->app->bind('command.adwords:token', GenerateRefreshTokenCommand::class);
34
        $this->commands([
35
            'command.adwords:token',
36
        ]);
37
38
39
        $this->app->bind(AdWordsService::class, function () use ($adwordsConfig) {
40
            return AdWordsServiceFactory::createForConfig($adwordsConfig);
41
        });
42
43
        $this->app->bind(AdWords::class, function () use ($adwordsConfig) {
44
            $this->guardAgainstInvalidConfiguration($adwordsConfig);
45
46
            $adWordsService = app(AdWordsService::class);
47
48
            return new AdWords($adWordsService);
49
        });
50
51
        $this->app->alias(AdWords::class, 'laravel-adwords-targeting-idea-service');
52
    }
53
54
    protected function guardAgainstInvalidConfiguration(array $adwordsConfig = null)
55
    {
56
        if (empty($adwordsConfig['developer_token'])) {
57
            throw InvalidConfiguration::developerTokenNotSpecified();
58
        }
59
    }
60
}
61