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

GlobalPrefixConfig   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

2 Methods

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