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   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 53
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fromAmountAndCurrency() 0 7 1
A toFloat() 0 5 1
A getDecimalFactor() 0 5 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