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

SatoshiCurrencies   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 28
ccs 0
cts 11
cp 0
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A contains() 0 3 1
A getIterator() 0 5 1
A subunitFor() 0 9 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 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