Passed
Push — master ( 19314b...2abb4b )
by Gabriel
05:40
created

CurrencyTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 35
ccs 13
cts 14
cp 0.9286
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A moneyHTMLFormat() 0 20 3
A getCode() 0 3 1
1
<?php
2
3
namespace ByTIC\Money\Models\Currencies;
4
5
/**
6
 * Trait CurrencyTrait.
7
 *
8
 * @property string $code
9
 * @property string $symbol
10
 * @property string $position
11
 */
12
trait CurrencyTrait
13
{
14
    /**
15
     * @return string
16
     */
17 1
    public function getCode()
18
    {
19 1
        return $this->getAttributeFromArray('code');
0 ignored issues
show
Bug introduced by
It seems like getAttributeFromArray() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
        return $this->/** @scrutinizer ignore-call */ getAttributeFromArray('code');
Loading history...
20
    }
21
22
    /**
23
     * @param $amount
24
     *
25
     * @return string
26
     */
27 5
    public function moneyHTMLFormat($amount)
28
    {
29 5
        $amount = strpos($amount, '.') !== false ? $amount : $amount . '.0';
30
31 5
        list($integerValue, $decimalValue) = explode('.', $amount);
32 5
        $intHTML = '<span class="money-int">'.number_format($integerValue).'</span>';
0 ignored issues
show
Bug introduced by
$integerValue of type string is incompatible with the type double expected by parameter $number of number_format(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

32
        $intHTML = '<span class="money-int">'.number_format(/** @scrutinizer ignore-type */ $integerValue).'</span>';
Loading history...
33
34 5
        $decimalValue = str_pad($decimalValue, 2, '0', STR_PAD_LEFT);
35 5
        $decimalHTML = '<sup class="money-decimal">.'.$decimalValue.'</sup>';
36
37 5
        $return = $intHTML.$decimalHTML;
38
39 5
        $symbolHTML = '<span class="money-currency">'.$this->symbol.'</span>';
40 5
        if ($this->position == 'before') {
41
            $return = $symbolHTML.' '.$amount;
42
        } else {
43 5
            $return .= ' '.$symbolHTML;
44
        }
45
46 5
        return '<span class="price" content="'.$amount.'">'.$return.'</span>';
47
    }
48
}
49