OhDearServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 29 4
A register() 0 4 1
1
<?php
2
3
namespace OhDear\LaravelOhDear;
4
5
use OhDear\PhpSdk\OhDear;
6
use OhDear\PhpSdk\Resources\Site;
7
use Illuminate\Support\ServiceProvider;
8
use OhDear\LaravelOhDear\Exceptions\ConfigNotCorrect;
9
10
class OhDearServiceProvider extends ServiceProvider
11
{
12
    public function boot()
13
    {
14
        if ($this->app->runningInConsole()) {
15
            $this->publishes([
16
                __DIR__.'/../config/oh-dear.php' => config_path('oh-dear.php'),
17
            ], 'config');
18
        }
19
20
        $this->app->singleton(OhDear::class, function () {
21
            $token = config('oh-dear.api_token');
22
23
            if (! $token) {
24
                dump('here');
25
                throw ConfigNotCorrect::apiTokenMissing();
26
            }
27
28
            return new OhDear($token);
29
        });
30
31
        $this->app->alias(OhDear::class, 'oh-dear');
32
33
        $this->app->bind(Site::class, function () {
34
            if (! $siteUrl = config('oh-dear.site_url')) {
35
                throw ConfigNotCorrect::siteUrlMissing();
36
            }
37
38
            return app(OhDear::class)->siteByUrl($siteUrl);
39
        });
40
    }
41
42
    public function register()
43
    {
44
        $this->mergeConfigFrom(__DIR__.'/../config/oh-dear.php', 'oh-dear');
45
    }
46
}
47