Currency   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getSymbol() 0 10 2
1
<?php
2
3
namespace hiqdev\yii2\merchant\models;
4
5
use NumberFormatter;
6
use Yii;
7
use yii\base\Model;
8
9
/**
10
 * Class Currency
11
 *
12
 * @author Dmytro Naumenko <[email protected]>
13
 */
14
class Currency extends Model
15
{
16
    /** @var string */
17
    public $code;
18
19
    /**
20
     * Returns the symbol used for a currency.
21
     *
22
     * @param string|null $locale   optional
23
     *
24
     * @return string|null the currency symbol or NULL if not found
25
     * @see https://stackoverflow.com/questions/13897516/get-currency-symbol-in-php
26
     */
27
    public function getSymbol($locale = null): string
28
    {
29
        if (null === $locale) {
30
            $locale = Yii::$app->formatter->locale;
31
        }
32
        $fmt = new NumberFormatter($locale . "@currency={$this->code}", NumberFormatter::CURRENCY);
33
        $symbol = $fmt->getSymbol(NumberFormatter::CURRENCY_SYMBOL);
34
35
        return $symbol;
36
    }
37
}
38