CurrencyExtension   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A NiceDecimalPoint() 0 14 3
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