HasCurrencyRecord   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 7
c 1
b 0
f 1
dl 0
loc 33
ccs 0
cts 9
cp 0
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCurrenciesManager() 0 3 1
A initCurrency() 0 3 1
A getCurrency() 0 7 2
1
<?php
2
3
namespace ByTIC\Money\Models\Currencies;
4
5
use ByTIC\Money\Models\Currencies\CurrenciesTrait as Currency;
6
use ByTIC\Money\Models\Currencies\CurrencyTrait as Currencies;
7
use Nip\Records\Locator\ModelLocator;
8
9
/**
10
 * Class HasCurrencyRecord.
11
 */
12
trait HasCurrencyRecord
13
{
14
    protected $currencyObject;
15
16
    /**
17
     * @return Currency
18
     */
19
    public function getCurrency()
20
    {
21
        if ($this->currencyObject === null) {
22
            $this->initCurrency();
23
        }
24
25
        return $this->currencyObject;
26
    }
27
28
    public function initCurrency()
29
    {
30
        $this->currencyObject = $this->getCurrenciesManager()->getByCode($this->getCurrencyCode());
31
    }
32
33
    /**
34
     * @return \Nip\Records\AbstractModels\RecordManager|CurrenciesTrait
35
     */
36
    public function getCurrenciesManager()
37
    {
38
        return currencyManager();
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    abstract public function getCurrencyCode();
45
}
46