GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

MoneyConverter::getDecimalFactor()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace CMPayments\PaymentSdk;
4
5
use Money\Currencies\ISOCurrencies;
6
use Money\Currency;
7
use Money\Money;
8
9
/**
10
 * Class MoneyFactory provides convenience methods to make it easier to interact with different parts of the SDK.
11
 *
12
 * @package CMPayments\PaymentSdk
13
 * @author  Jory Geerts <[email protected]>
14
 */
15
class MoneyConverter
16
{
17
18
    /**
19
     * @var ISOCurrencies
20
     */
21
    private $isoCurrencies;
22
23
    /**
24
     * CreateChargeRequest constructor.
25
     */
26 11
    public function __construct()
27
    {
28 11
        $this->isoCurrencies = new ISOCurrencies();
29 11
    }
30
31
    /**
32
     * Create a money object from a (float) amount and a currency.
33
     *
34
     * @param float  $amount
35
     * @param string $currencyCode
36
     * @return Money
37
     */
38 1
    public function fromAmountAndCurrency($amount, $currencyCode)
39
    {
40 1
        $currency = new Currency($currencyCode);
41 1
        $decimalFactor = $this->getDecimalFactor($currency);
42
43 1
        return new Money($amount * $decimalFactor, $currency);
44
    }
45
46
    /**
47
     * @param Money $money
48
     * @return float
49
     */
50 10
    public function toFloat(Money $money)
51
    {
52 10
        $decimalFactor = $this->getDecimalFactor($money->getCurrency());
53 10
        return $money->getAmount() / $decimalFactor;
54
    }
55
56
    /**
57
     * Calculate the decimal factor for a currency
58
     *
59
     * @param Currency $currency
60
     * @return integer
61
     */
62 11
    private function getDecimalFactor(Currency $currency)
63
    {
64 11
        $subunitSize = $this->isoCurrencies->subunitFor($currency);
65 11
        return pow(10, $subunitSize);
66
    }
67
}
68