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

BitcoinCurrencies::contains()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
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 BitcoinCurrencies implements Currencies
18
{
19
    public const BTC = 'BTC';
20
    public const XBT = 'XBT';
21
22
    public const SYMBOL = "\u{20BF}";
23
24
    public function contains(Currency $currency): bool
25
    {
26
        return in_array($currency->getCode(), [self::BTC, self::XBT]);
27
    }
28
29
    public function subunitFor(Currency $currency): int
30
    {
31
        if (!$this->contains($currency)) {
32
            throw new UnknownCurrencyException(
33
                $currency.' is not Bitcoin and is not supported by this currency repository.'
34
            );
35
        }
36
37
        return 8;
38
    }
39
40
    public function getIterator(): Traversable
41
    {
42
        return new ArrayIterator([
43
            new Currency(self::BTC),
44
            new Currency(self::XBT),
45
        ]);
46
    }
47
}
48