Completed
Push — master ( 0820ba...224783 )
by ARCANEDEV
8s
created

ManagerServiceProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 98
rs 10
ccs 38
cts 38
cp 1
wmc 7
lcom 1
cbo 6

7 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 1
A boot() 0 6 1
A provides() 0 11 1
A registerCurrencyManager() 0 11 1
A registerCurrencyConverter() 0 8 1
A registerHttpClient() 0 8 1
A loadCurrencies() 0 9 1
1
<?php namespace Arcanedev\Currencies\Providers;
2
3
use Arcanedev\Currencies\Contracts\ConverterManager as ConverterManagerContract;
4
use Arcanedev\Currencies\Contracts\CurrencyManager as CurrencyManagerContract;
5
use Arcanedev\Currencies\Contracts\Http\Client as HttpClientContract;
6
use Arcanedev\Currencies\ConverterManager;
7
use Arcanedev\Currencies\CurrencyManager;
8
use Arcanedev\Support\ServiceProvider;
9
10
/**
11
 * Class     ManagerServiceProvider
12
 *
13
 * @package  Arcanedev\Currencies\Providers
14
 * @author   ARCANEDEV <[email protected]>
15
 */
16
class ManagerServiceProvider extends ServiceProvider
17
{
18
    /* ------------------------------------------------------------------------------------------------
19
     |  Properties
20
     | ------------------------------------------------------------------------------------------------
21
     */
22
    /**
23
     * Indicates if loading of the provider is deferred.
24
     *
25
     * @var bool
26
     */
27
    protected $defer = true;
28
29
    /* ------------------------------------------------------------------------------------------------
30
     |  Main Functions
31
     | ------------------------------------------------------------------------------------------------
32
     */
33
    /**
34
     * Register the service provider.
35
     */
36 540
    public function register()
37
    {
38 540
        $this->registerHttpClient();
39 540
        $this->registerCurrencyManager();
40 540
        $this->registerCurrencyConverter();
41 540
    }
42
43
    /**
44
     * Boot the service provider.
45
     */
46 540
    public function boot()
47
    {
48 540
        parent::boot();
49
50 540
        $this->loadCurrencies();
51 540
    }
52
53
    /**
54
     * Get the services provided by the provider.
55
     *
56
     * @return array
57
     */
58 21
    public function provides()
59
    {
60
        return [
61 21
            'arcanedev.currencies.http-client',
62 9
            HttpClientContract::class,
63 9
            'arcanedev.currencies.manager',
64 9
            CurrencyManagerContract::class,
65 9
            'arcanedev.currencies.converter',
66 9
            ConverterManagerContract::class,
67 9
        ];
68
    }
69
70
    /* ------------------------------------------------------------------------------------------------
71
     |  Other Functions
72
     | ------------------------------------------------------------------------------------------------
73
     */
74 540
    private function registerCurrencyManager()
75
    {
76
        $this->singleton('arcanedev.currencies.manager', function ($app) {
77
            /** @var \Illuminate\Contracts\Config\Repository $config */
78 540
            $config  = $app['config'];
79
80 540
            return new CurrencyManager($config->get('currencies'));
81 540
        });
82
83 540
        $this->app->bind(CurrencyManagerContract::class, 'arcanedev.currencies.manager');
84 540
    }
85
86 540
    private function registerCurrencyConverter()
87
    {
88
        $this->singleton('arcanedev.currencies.converter', function ($app) {
89 36
            return new ConverterManager($app);
90 540
        });
91
92 540
        $this->app->bind(ConverterManagerContract::class, 'arcanedev.currencies.converter');
93 540
    }
94
95
    private function registerHttpClient()
96
    {
97 540
        $this->bind('arcanedev.currencies.http-client', function () {
98 24
            return new \Arcanedev\Currencies\Http\Client;
99 540
        });
100
101 540
        $this->bind(HttpClientContract::class, 'arcanedev.currencies.http-client');
102 540
    }
103
104 540
    private function loadCurrencies()
105
    {
106
        /** @var \Illuminate\Contracts\Config\Repository $config */
107 540
        $config  = $this->app['config'];
108
109
        /** @var CurrencyManagerContract $manager */
110 540
        $manager = $this->app->make('arcanedev.currencies.manager');
111 540
        $manager->load($config->get('currencies.data', []));
112 540
    }
113
}
114