RevolutServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 34
c 2
b 0
f 1
dl 0
loc 69
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 35 2
A boot() 0 19 3
1
<?php
2
3
namespace tbclla\Revolut\Providers;
4
5
use Illuminate\Contracts\Cache\Factory as CacheFactory;
6
use Illuminate\Support\ServiceProvider;
7
use tbclla\Revolut\Auth\ClientAssertion;
8
use tbclla\Revolut\Auth\Requests\AuthorizationCodeRequest;
9
use tbclla\Revolut\Client;
10
use tbclla\Revolut\Console\Commands\AccessTokenCommand;
11
use tbclla\Revolut\Console\Commands\AuthorizeCommand;
12
use tbclla\Revolut\Console\Commands\CleanupCommand;
13
use tbclla\Revolut\Console\Commands\JWTCommand;
14
use tbclla\Revolut\Console\Commands\ResetCommand;
15
use tbclla\Revolut\GuzzleHttpClient;
16
use tbclla\Revolut\Interfaces\MakesHttpRequests;
17
use tbclla\Revolut\Interfaces\TokenRepository;
18
use tbclla\Revolut\Repositories\CacheTokenRepository;
19
use tbclla\Revolut\Repositories\DatabaseTokenRepository;
20
21
class RevolutServiceProvider extends ServiceProvider
22
{
23
    /**
24
     * Register services.
25
     *
26
     * @return void
27
     */
28
    public function register()
29
    {
30
        $this->app->bind(CacheTokenRepository::class, function() {
31
            return new CacheTokenRepository(
32
                resolve(CacheFactory::class),
33
                config('revolut.tokens.cache.driver')
34
            );
35
        });
36
37
        $this->app->bind(TokenRepository::class, function() {
38
            return config('revolut.tokens.store') === 'database'
39
                ? new DatabaseTokenRepository
40
                :  resolve(CacheTokenRepository::class);
41
        });
42
43
        $this->app->bind(MakesHttpRequests::class, GuzzleHttpClient::class);
44
45
        $this->app->bind(ClientAssertion::class, function() {
46
            return new ClientAssertion(
47
                config('revolut.client_id'),
48
                config('revolut.private_key'),
49
                config('revolut.redirect_uri')
50
            );
51
        });
52
53
        $this->app->bind(AuthorizationCodeRequest::class, function() {
54
            return new AuthorizationCodeRequest(
55
                config('revolut.client_id'),
56
                config('revolut.redirect_uri'),
57
                config('revolut.sandbox')
58
            );
59
        });
60
61
        $this->app->singleton('revolut', function() {
62
            return resolve(Client::class);
63
        });
64
    }
65
66
    /**
67
     * Bootstrap services.
68
     *
69
     * @return void
70
     */
71
    public function boot()
72
    {
73
        $this->publishes([
74
            __DIR__ . '/../config/revolut.php' => config_path('revolut.php')
75
        ]);
76
77
        if (config('revolut.tokens.store') === 'database') {
78
            $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
79
        }
80
        
81
        $this->loadRoutesFrom(__DIR__ . '/../routes/web.php');
82
83
        if ($this->app->runningInConsole()) {
84
            $this->commands([
85
                JWTCommand::class,
86
                CleanupCommand::class,
87
                ResetCommand::class,
88
                AuthorizeCommand::class,
89
                AccessTokenCommand::class,
90
            ]);
91
        }
92
    }
93
}
94