Manager   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 50
ccs 13
cts 14
cp 0.9286
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 3 1
A get() 0 6 2
A create() 0 7 2
A createHtmlFormatter() 0 4 1
1
<?php
2
3
namespace ByTIC\Money\Formatter;
4
5
use InvalidArgumentException;
6
use Money\Currencies\ISOCurrencies;
7
use Money\MoneyFormatter;
8
use Nip\Cache\Stores\Repository;
9
use Nip\Utility\Traits\SingletonTrait;
10
11
/**
12
 * Class Manager
13
 * @package ByTIC\Money\Formatter
14
 */
15
class Manager
16
{
17
    use SingletonTrait;
18
19
    protected $formatters = [];
20
21
    /**
22
     * @param $name
23
     * @return MoneyFormatter
24
     */
25 2
    public function get($name)
26
    {
27 2
        if (!isset($this->formatters[$name])) {
28 2
            $this->formatters[$name] = $this->resolve($name);
29
        }
30 2
        return $this->formatters[$name];
31
    }
32
33
    /**
34
     * @param $name
35
     * @return Repository
36
     */
37 1
    protected function resolve($name)
38
    {
39 1
        return $this->create($name, []);
40
    }
41
42
    /**
43
     * @param $name
44
     * @param array $config
45
     * @return mixed
46
     */
47 1
    protected function create($name, $config = [])
48
    {
49 1
        $driverMethod = 'create' . ucfirst($name) . 'Formatter';
50 1
        if (method_exists($this, $driverMethod)) {
51 1
            return $this->{$driverMethod}($config);
52
        } else {
53
            throw new InvalidArgumentException("Driver [{$name}] is not supported.");
54
        }
55
    }
56
57
    /**
58
     * @param array $config
59
     * @return HtmlFormatter
60
     */
61 1
    protected function createHtmlFormatter($config = [])
62
    {
63 1
        $formatter = new HtmlFormatter(new ISOCurrencies());
64 1
        return $formatter;
65
    }
66
}
67