ClientServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 1
b 0
f 0
dl 0
loc 52
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A provides() 0 5 1
A boot() 0 2 1
A register() 0 5 1
A registerClient() 0 10 1
1
<?php
2
3
namespace Spinen\Halo\Providers;
4
5
use GuzzleHttp\Client as Guzzle;
6
use Illuminate\Contracts\Foundation\Application;
7
use Illuminate\Contracts\Support\DeferrableProvider;
8
use Illuminate\Support\Facades\Config;
9
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
10
use Spinen\Halo\Api\Client as Halo;
11
use Spinen\Halo\Support\Builder;
12
13
/**
14
 * Class ClientServiceProvider
15
 *
16
 * Since this is deferred, it only needed to deal with code that has to do with the client.
17
 */
18
class ClientServiceProvider extends LaravelServiceProvider implements DeferrableProvider
19
{
20
    /**
21
     * Bootstrap services.
22
     *
23
     * @return void
24
     */
25
    public function boot()
26
    {
27
        //
28
    }
29
30
    /**
31
     * Register services.
32
     *
33
     * @return void
34
     */
35
    public function register()
36
    {
37
        $this->registerClient();
38
39
        $this->app->alias(Halo::class, 'Halo');
40
    }
41
42
    /**
43
     * Get the services provided by the provider.
44
     *
45
     * @return array
46
     */
47
    public function provides()
48
    {
49
        return [
50
            Builder::class,
51
            Halo::class,
52
        ];
53
    }
54
55
    /**
56
     * Register the client
57
     *
58
     * If the Halo id or roles are null, then assume sensible values via the API
59
     */
60
    protected function registerClient(): void
61
    {
62
        $this->app->bind(
63
            abstract: Builder::class,
64
            concrete: fn (Application $app): Builder => (new Builder())->setClient($app->make(Halo::class))
65
        );
66
67
        $this->app->bind(
68
            abstract: Halo::class,
69
            concrete: fn (Application $app): Halo => new Halo(Config::get('halo'), $app->make(Guzzle::class))
70
        );
71
    }
72
}
73