Test Failed
Push — master ( 257d98...3364ef )
by Yunus Emre
06:12
created

ParasutServiceProvider::mergeConfigs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TarfinLabs\Parasut;
4
5
use Illuminate\Support\ServiceProvider;
6
use TarfinLabs\Parasut\API\ClientGateway;
7
use TarfinLabs\Parasut\API\HttpClientGateway;
8
9
class ParasutServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap the application services.
13
     */
14
    public function boot(): void
15
    {
16
        if ($this->app->runningInConsole()) {
17
            $this->publishConfigs();
18
        }
19
20
        $this->loadFactories();
21
    }
22
23
    /**
24
     * Register the application services.
25
     */
26
    public function register(): void
27
    {
28
        $this->mergeConfigs();
29
30
        // Register the main class to use with the facade
31
        $this->app->singleton(ClientGateway::class, fn () => new HttpClientGateway(
32
            config('parasut.grant_type'),
33
            config('parasut.client_id'),
34
            config('parasut.client_secret'),
35
            config('parasut.username'),
36
            config('parasut.password'),
37
            config('parasut.redirect_uri'),
38
        ));
39
    }
40
41
    /**
42
     * Merge the configs.
43
     */
44
    protected function mergeConfigs(): void
45
    {
46
        // Automatically apply the package configuration
47
        $this->mergeConfigFrom(__DIR__.'/../config/parasut.php', 'parasut');
48
    }
49
50
    /**
51
     * Publish the configs.
52
     */
53
    protected function publishConfigs(): void
54
    {
55
        $this->publishes([
56
            __DIR__.'/../config/parasut.php' => config_path('parasut.php'),
57
        ], 'config');
58
    }
59
60
    protected function loadFactories(): void
61
    {
62
        $this->loadFactoriesFrom(__DIR__.'/Factories');
63
    }
64
}
65