Completed
Push — master ( 7383a6...06d9f7 )
by ARCANEDEV
19s
created

CurrenciesServiceProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 97.06%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 4
dl 0
loc 119
ccs 33
cts 34
cp 0.9706
rs 10

7 Methods

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