Completed
Push — master ( abcf31...a8a46d )
by thomas
28:08 queued 25:46
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
declare(strict_types=1);
4
5
namespace BitWasp\Bitcoin\Key\Deterministic\HdPrefix;
6
7
use BitWasp\Bitcoin\Network\NetworkInterface;
8
9
class GlobalPrefixConfig
10
{
11
    /**
12
     * @var NetworkConfig[]
13
     */
14
    private $networkConfigs = [];
15
16
    /**
17
     * ScriptPrefixConfig constructor.
18
     * @param NetworkConfig[] $config
19
     */
20 12
    public function __construct(array $config)
21
    {
22 12
        foreach ($config as $networkPrefixConfig) {
23 12
            if (!($networkPrefixConfig instanceof NetworkConfig)) {
24 1
                throw new \InvalidArgumentException("expecting array of NetworkPrefixConfig");
25
            }
26
27 11
            $networkClass = get_class($networkPrefixConfig->getNetwork());
28 11
            if (array_key_exists($networkClass, $this->networkConfigs)) {
29 1
                throw new \InvalidArgumentException("multiple configs for network");
30
            }
31
32 11
            $this->networkConfigs[$networkClass] = $networkPrefixConfig;
33
        }
34 10
    }
35
36
    /**
37
     * @param NetworkInterface $network
38
     * @return NetworkConfig
39
     */
40 10
    public function getNetworkConfig(NetworkInterface $network): NetworkConfig
41
    {
42 10
        $class = get_class($network);
43 10
        if (!array_key_exists($class, $this->networkConfigs)) {
44 1
            throw new \InvalidArgumentException("Network not registered with GlobalHdPrefixConfig");
45
        }
46
47 9
        return $this->networkConfigs[$class];
48
    }
49
}
50