Passed
Push — master ( 365cfc...8e997c )
by Mr
04:36
created

SatoshiMoneyFormatter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 16
ccs 0
cts 10
cp 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A format() 0 7 2
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().SatoshiCurrencies::MSAT;
32
    }
33
}
34