Completed
Pull Request — 0.0.35 (#659)
by thomas
26:42
created

GlobalHdKeyPrefixConfig   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A getNetworkHdPrefixConfig() 0 9 2
1
<?php
2
3
namespace BitWasp\Bitcoin\Serializer\Key\ScriptedHierarchicalKey;
4
5
use BitWasp\Bitcoin\Network\NetworkInterface;
6
7
class GlobalHdKeyPrefixConfig
8
{
9
    /**
10
     * @var NetworkHdKeyPrefixConfig[]
11
     */
12
    private $networkConfigs = [];
13
14
    /**
15
     * ScriptPrefixConfig constructor.
16
     * @param NetworkHdKeyPrefixConfig[] $config
17
     */
18 1
    public function __construct(array $config)
19
    {
20 1
        foreach ($config as $networkPrefixConfig) {
21 1
            $networkClass = get_class($networkPrefixConfig->getNetwork());
22 1
            if (!array_key_exists($networkClass, $this->networkConfigs)) {
23 1
                $this->networkConfigs[$networkClass] = [];
24
            }
25
26 1
            $this->networkConfigs[$networkClass] = $networkPrefixConfig;
27
        }
28 1
    }
29
30
    /**
31
     * @param NetworkInterface $network
32
     * @return NetworkHdKeyPrefixConfig
33
     */
34 1
    public function getNetworkHdPrefixConfig(NetworkInterface $network)
35
    {
36 1
        $class = get_class($network);
37 1
        if (!array_key_exists($class, $this->networkConfigs)) {
38
            throw new \InvalidArgumentException("Network not registered with GlobalHdPrefixConfig");
39
        }
40
41 1
        return $this->networkConfigs[$class];
42
    }
43
}
44