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

ConverterManager::config()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php namespace Arcanedev\Currencies;
2
3
use Arcanedev\Currencies\Contracts\ConverterManager as ConverterManagerContract;
4
use Illuminate\Support\Manager;
5
6
/**
7
 * Class     ConverterManager
8
 *
9
 * @package  Arcanedev\Currencies
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class ConverterManager extends Manager implements ConverterManagerContract
13
{
14
    /* ------------------------------------------------------------------------------------------------
15
     |  Main Functions
16
     | ------------------------------------------------------------------------------------------------
17
     */
18
    /**
19
     * Create an instance of the specified driver.
20
     *
21
     * @return \Arcanedev\Currencies\Contracts\CurrencyConverter
22
     */
23
    protected function createOpenexchangeratesDriver()
24
    {
25
        return $this->buildProvider(
26
            \Arcanedev\Currencies\Converters\OpenExchangeRatesConverter::class,
27
            $this->getProviderConfigs('openexchangerates')
28
        );
29
    }
30
31
    /**
32
     * Get the default driver name.
33
     *
34
     * @throws \InvalidArgumentException
35
     *
36
     * @return string
37
     */
38
    public function getDefaultDriver()
39
    {
40
        return $this->config()->get('currencies.converters.default');
41
    }
42
43
    /* ------------------------------------------------------------------------------------------------
44
     |  Other Functions
45
     | ------------------------------------------------------------------------------------------------
46
     */
47
    /**
48
     * Get the config repository instance.
49
     *
50
     * @return \Illuminate\Contracts\Config\Repository
51
     */
52
    protected function config()
53
    {
54
        return $this->app['config'];
55
    }
56
57
    /**
58
     * Get the provider configs.
59
     *
60
     * @param  string  $provider
61
     *
62
     * @return array
63
     */
64
    protected function getProviderConfigs($provider)
65
    {
66
        $configs          = $this->config()->get("currencies.converters.providers.$provider");
67
        $configs['cache'] = $this->config()->get("currencies.converters.cache");
68
69
        return $configs;
70
    }
71
72
    /**
73
     * Build the converter provider.
74
     *
75
     * @param  string  $provider
76
     * @param  array   $configs
77
     *
78
     * @return \Arcanedev\Currencies\Contracts\CurrencyConverter
79
     */
80
    protected function buildProvider($provider, array $configs)
81
    {
82
        return new $provider(
83
            new \Arcanedev\Currencies\Http\Client,
84
            $this->app['cache']->driver(),
85
            $configs
86
        );
87
    }
88
}
89