CurrencyTrait::getCode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 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