SatoshiMoneyFormatter::format()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 0
cts 4
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the ngutech/bitcoin-interop project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace NGUtech\Bitcoin\Service;
10
11
use Money\Currencies;
12
use Money\Exception\FormatterException;
13
use Money\Money;
14
use Money\MoneyFormatter;
15
16
final class SatoshiMoneyFormatter implements MoneyFormatter
17
{
18
    private Currencies $currencies;
19
20
    public function __construct(Currencies $currencies)
21
    {
22
        $this->currencies = $currencies;
23
    }
24
25
    public function format(Money $money): string
26
    {
27
        if (!$this->currencies->contains($money->getCurrency())) {
28
            throw new FormatterException('Satoshi formatter can only format Satoshi currencies.');
29
        }
30
31
        return $money->getAmount().$money->getCurrency()->getCode();
32
    }
33
}
34