Currency   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 59
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getCurrencyName() 0 8 2
A getCurrencySymbol() 0 8 2
A getDefaultCurrency() 0 4 1
1
<?php
2
3
namespace Flagbit\Bundle\CurrencyBundle\Service;
4
5
use Symfony\Component\Intl\ResourceBundle\CurrencyBundleInterface;
6
7
class Currency
8
{
9
    /**
10
     * @var string
11
     */
12
    private $defaultCurrency;
13
14
    /**
15
     * @var CurrencyBundleInterface
16
     */
17
    private $currencyBundle;
18
19
    /**
20
     *
21
     * @param CurrencyBundleInterface $currencyBundle
22
     * @param string                  $defaultCurrency ISO 4217 currency code
23
     */
24 9
    public function __construct(CurrencyBundleInterface $currencyBundle, $defaultCurrency)
25
    {
26 9
        $this->currencyBundle = $currencyBundle;
27 9
        $this->defaultCurrency = $defaultCurrency;
28 9
    }
29
30
    /**
31
     * @param string $currency ISO 4217 currency code
32
     *
33
     * @return string Name like "Euro" or "Schweizer Franken"
34
     */
35 3
    public function getCurrencyName($currency = null)
36
    {
37 3
        if (null === $currency) {
38 2
            $currency = $this->defaultCurrency;
39
        }
40
41 3
        return $this->currencyBundle->getCurrencyName($currency);
42
    }
43
44
    /**
45
     * @param string $currency ISO 4217 currency code
46
     *
47
     * @return string Symbol like "€" or "CHF"
48
     */
49 3
    public function getCurrencySymbol($currency = null)
50
    {
51 3
        if (null === $currency) {
52 2
            $currency = $this->defaultCurrency;
53
        }
54
55 3
        return $this->currencyBundle->getCurrencySymbol($currency);
56
    }
57
58
    /**
59
     * @return string ISO 4217 currency code
60
     */
61 4
    public function getDefaultCurrency()
62
    {
63 4
        return $this->defaultCurrency;
64
    }
65
}
66