CurrencyTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 78.56%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 15
c 1
b 0
f 1
dl 0
loc 34
ccs 11
cts 14
cp 0.7856
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCode() 0 3 1
A moneyHTMLFormat() 0 20 2
1
<?php
2
3
namespace ByTIC\Payments\Models\Currencies\Traits;
4
5
/**
6
 * Trait CurrencyTrait
7
 * @package ByTIC\Payments\Models\Currencies\Traits
8
 *
9
 * @property string $code
10
 * @property string $symbol
11
 * @property string $position
12
 */
13
trait CurrencyTrait
14
{
15
    /**
16
     * @return string
17
     */
18
    public function getCode()
19
    {
20
        return $this->code;
21
    }
22
23
    /**
24
     * @param $amount
25
     * @return string
26
     */
27 4
    public function moneyHTMLFormat($amount)
28
    {
29 4
        $integerValue = floor($amount);
30 4
        $decimalValue = round(($amount - $integerValue)*100, 0);
31 4
        $intHTML = '<span class="money-int">'.number_format($integerValue).'</span>';
32
33
        $decimalHTML = '<sup class="money-decimal">.'
34 4
            .str_pad($decimalValue, 2, '0', STR_PAD_LEFT)
35 4
            .'</sup>';
36
37 4
        $return = $intHTML.$decimalHTML;
38
39 4
        $symbolHTML = '<span class="money-currency">'.$this->symbol.'</span>';
40 4
        if ($this->position == 'before') {
41
            $return = $symbolHTML.' '.$amount;
42
        } else {
43 4
            $return .= ' '.$symbolHTML;
44
        }
45
46 4
        return '<span class="price" content="'.$amount.'">'.$return.'</span>';
47
    }
48
}
49