HasCurrencyRecord::initCurrency()   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
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
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