CurrenciesTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 34
ccs 0
cts 7
cp 0
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getByCode() 0 3 1
A convert() 0 7 1
1
<?php
2
3
namespace ByTIC\Money\Models\Currencies;
4
5
/**
6
 * trait CurrenciesTrait.
7
 *
8
 * @method CurrencyTrait[] getAll()
9
 * @method CurrencyTrait findByCode($code)
10
 */
11
trait CurrenciesTrait
12
{
13
    /**
14
     * @param $from
15
     * @param $to
16
     * @param $amount
17
     *
18
     * @return float|int
19
     */
20
    public function convert($from, $to, $amount)
21
    {
22
        $rates['eur'] = '1';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$rates was never initialized. Although not strictly required by PHP, it is generally a good practice to add $rates = array(); before regardless.
Loading history...
23
        $rates['bgn'] = '0.5113';
24
        $rates['ron'] = '0.2260';
25
26
        return $amount * $rates[$from] / $rates[$to];
27
    }
28
29
    /**
30
     * @param $code
31
     *
32
     * @return CurrencyTrait
33
     */
34
    public function getByCode($code)
35
    {
36
        return $this->findOne($code);
37
    }
38
39
    /**
40
     * @param $id
41
     *
42
     * @return CurrencyTrait
43
     */
44
    abstract public function findOne($id);
45
}
46