FlagbitCurrencyExtension::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Flagbit\Bundle\CurrencyBundle\Twig;
4
5
use Flagbit\Bundle\CurrencyBundle\Service\Currency;
6
use Twig_Extension;
7
use Twig_Extension_GlobalsInterface;
8
9
class FlagbitCurrencyExtension extends Twig_Extension implements Twig_Extension_GlobalsInterface
10
{
11
    /**
12
     * @var Currency
13
     */
14
    private $currency;
15
16
    /**
17
     * @param Currency $currency
18
     */
19 4
    public function __construct(Currency $currency)
20
    {
21 4
        $this->currency = $currency;
22 4
    }
23
24
    /**
25
     * Returns the name of the extension.
26
     *
27
     * @return string The extension name
28
     */
29 3
    public function getName()
30
    {
31 3
        return 'flagbit_currency';
32
    }
33
34
    /**
35
     * @return array
36
     */
37 3
    public function getFunctions()
38
    {
39 3
        $currencyService = $this->currency;
40
41
        return [
42
            new \Twig_SimpleFunction('currency_name', function ($currency = null) use ($currencyService) {
43 1
                return $currencyService->getCurrencyName($currency);
44 3
            }),
45 3
            new \Twig_SimpleFunction('currency_symbol', function ($currency = null) use ($currencyService) {
46 1
                return $currencyService->getCurrencySymbol($currency);
47 3
            }),
48
        ];
49
    }
50
51
    /**
52
     * @return array
53
     */
54 3
    public function getGlobals()
55
    {
56
        return [
57
            'currency' => [
58 3
                'default' => $this->currency->getDefaultCurrency(),
59
            ],
60
        ];
61
    }
62
}
63