Completed
Pull Request — 0.0.35 (#659)
by thomas
25:40
created

GlobalPrefixConfig::getNetworkHdPrefixConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
ccs 4
cts 5
cp 0.8
crap 2.032
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace BitWasp\Bitcoin\Key\Deterministic\HdPrefix;
4
5
use BitWasp\Bitcoin\Network\NetworkInterface;
6
use BitWasp\Bitcoin\Key\Deterministic\HdPrefix\NetworkPrefixConfig;
7
8
class GlobalPrefixConfig
9
{
10
    /**
11
     * @var NetworkPrefixConfig[]
12
     */
13
    private $networkConfigs = [];
14
15
    /**
16
     * ScriptPrefixConfig constructor.
17
     * @param NetworkPrefixConfig[] $config
18
     */
19 1
    public function __construct(array $config)
20
    {
21 1
        foreach ($config as $networkPrefixConfig) {
22 1
            $networkClass = get_class($networkPrefixConfig->getNetwork());
23 1
            if (!array_key_exists($networkClass, $this->networkConfigs)) {
24 1
                $this->networkConfigs[$networkClass] = [];
25
            }
26
27 1
            $this->networkConfigs[$networkClass] = $networkPrefixConfig;
28
        }
29 1
    }
30
31
    /**
32
     * @param NetworkInterface $network
33
     * @return NetworkPrefixConfig
34
     */
35 1
    public function getNetworkHdPrefixConfig(NetworkInterface $network)
36
    {
37 1
        $class = get_class($network);
38 1
        if (!array_key_exists($class, $this->networkConfigs)) {
39
            throw new \InvalidArgumentException("Network not registered with GlobalHdPrefixConfig");
40
        }
41
42 1
        return $this->networkConfigs[$class];
43
    }
44
}
45