HunterServiceProvider::getConfig()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
namespace Messerli90\Hunterio;
4
5
use Illuminate\Support\ServiceProvider;
6
use Messerli90\Hunterio\Exceptions\AuthorizationException;
7
8
class HunterServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     */
13
    public function boot()
14
    {
15
16
        if ($this->app->runningInConsole()) {
17
            $this->publishes([
18
                __DIR__ . '/../config/config.php' => config_path('hunter.php'),
19
            ], 'config');
20
        }
21
    }
22
23
    /**
24
     * Register the application services.
25
     */
26
    public function register()
27
    {
28
        $this->app->bind(Hunter::class, function () {
29
            $api_key = $this->getConfig();
30
            return new Hunter($api_key);
31
        });
32
33
        $this->app->alias(Hunter::class, 'hunterio');
34
    }
35
36
    protected function getConfig()
37
    {
38
        if (config('hunter.key')) {
39
            return config('hunter.key');
40
        }
41
        if (config('services.hunter.key')) {
42
            return config('services.hunter.key');
43
        }
44
        throw new AuthorizationException('Could not find an API key.');
45
    }
46
}
47