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

GlobalPrefixConfig   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\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