MoneyFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 23
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 14 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Genkgo\Camt\Util;
6
7
use Money\Currencies\ISOCurrencies;
8
use Money\Currency;
9
use Money\Money;
10
use Money\Parser\DecimalMoneyParser;
11
use SimpleXMLElement;
12
13
final class MoneyFactory
14
{
15
    private DecimalMoneyParser $decimalMoneyParser;
16
17
    public function __construct()
18
    {
19
        $this->decimalMoneyParser = new DecimalMoneyParser(new ISOCurrencies());
20
    }
21
22
    public function create(SimpleXMLElement $xmlAmount, ?SimpleXMLElement $CdtDbtInd): Money
23
    {
24
        $amount = (string) $xmlAmount;
25
26
        if ((string) $CdtDbtInd === 'DBIT') {
27
            $amount = (string) ((float) $amount * -1);
28
        }
29
30
        /** @psalm-var non-empty-string $currency */
31
        $currency = (string) $xmlAmount['Ccy'];
32
33
        return $this->decimalMoneyParser->parse(
34
            $amount,
35
            new Currency($currency)
36
        );
37
    }
38
}
39