HunterServiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 9 2
A register() 0 9 1
A getConfig() 0 10 3
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