SatoshiCurrencies::subunitFor()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
ccs 0
cts 5
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 ArrayIterator;
12
use Money\Currencies;
13
use Money\Currency;
14
use Money\Exception\UnknownCurrencyException;
15
use Traversable;
16
17
final class SatoshiCurrencies implements Currencies
18
{
19
    public const SAT = 'SAT';
20
    public const MSAT = 'MSAT';
21
22
    public const SYMBOL = '';
23
24
    public function contains(Currency $currency): bool
25
    {
26
        return in_array($currency->getCode(), [self::SAT, self::MSAT]);
27
    }
28
29
    public function subunitFor(Currency $currency): int
30
    {
31
        if (!$this->contains($currency)) {
32
            throw new UnknownCurrencyException(
33
                $currency.' is not Satoshi and is not supported by this currency repository.'
34
            );
35
        }
36
37
        return 0;
38
    }
39
40
    public function getIterator(): Traversable
41
    {
42
        return new ArrayIterator([
43
            new Currency(self::SAT),
44
            new Currency(self::MSAT)
45
        ]);
46
    }
47
}
48