Completed
Push — master ( cc6ec1...3e4435 )
by Dan Michael O.
02:33
created

GoogleBooksServiceProvider::validateConfig()   A

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 Scriptotek\GoogleBooks;
4
5
use Illuminate\Foundation\Application;
6
use Illuminate\Support\ServiceProvider;
7
use Scriptotek\GoogleBooks\Exceptions\InvalidCOnfiguration;
8
9
/**
10
 * Laravel 5 service provider
11
 */
12
class GoogleBooksServiceProvider extends ServiceProvider
13
{
14
    /**
15
     * Bootstrap the application events.
16
     *
17
     * @return void
18
     */
19
    public function boot()
20
    {
21
        $this->publishes([
22
            __DIR__ . '/../config/config.php' => config_path('googlebooks.php')
23
        ]);
24
    }
25
26
    /**
27
     * Register the service provider.
28
     *
29
     * @return void
30
     */
31
    public function register()
32
    {
33
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'googlebooks');
34
35
        $this->app->singleton(GoogleBooks::class, function () {
36
            $config = config('googlebooks');
37
            $this->validateConfig($config);
38
            return new GoogleBooks($config);
39
        });
40
41
        $this->app->alias(GoogleBooks::class, 'googlebooks');
42
    }
43
44
    protected function validateConfig(array $config = null)
45
    {
46
        if (empty($config['key'])) {
47
            throw InvalidConfiguration::keyNotSpecified();
48
        }
49
    }
50
}
51