CurrencyExtension::NiceDecimalPoint()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
/**
3
 * CurrencyExtension.php
4
 *
5
 * @author Bram de Leeuw
6
 * Date: 27/03/17
7
 */
8
9
namespace Broarm\EventTickets;
10
11
use DataExtension;
12
use Currency;
13
14
/**
15
 * Class CurrencyExtension
16
 *
17
 * @property CurrencyExtension|Currency $owner
18
 */
19
class CurrencyExtension extends DataExtension
20
{
21
    private static $decimal_point = '.';
22
23
    private static $thousand_separator = ',';
24
25
    /**
26
     * Returns the number as a currency, eg “$1,000.00”.
27
     * Where the decimal point and thousand separator are configurable
28
     *
29
     * @return string
30
     */
31
    public function NiceDecimalPoint()
32
    {
33
        $currencySymbol = Currency::config()->get('currency_symbol');
34
        $decimalPoint = Currency::config()->get('decimal_point');
35
        $thousandSeparator = Currency::config()->get('thousand_seperator');
36
        $val = $currencySymbol . number_format(abs($this->owner->value), 2, $decimalPoint, $thousandSeparator);
37
        if ((double)$this->owner->value === (double)0) {
38
            return _t('CurrencyExtension.FREE', 'Free');
39
        } elseif ((double)$this->owner->value < 0) {
40
            return "($val)";
41
        } else {
42
            return $val;
43
        }
44
    }
45
}
46