Completed
Pull Request — 0.0.35 (#660)
by thomas
22:14
created

PrefixRegistry   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 78.56%

Importance

Changes 0
Metric Value
dl 0
loc 39
ccs 11
cts 14
cp 0.7856
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 15 7
A getPrefixes() 0 7 2
1
<?php
2
3
namespace BitWasp\Bitcoin\Key\Deterministic\Slip132;
4
5
class PrefixRegistry
6
{
7
    /**
8
     * @var array
9
     */
10
    private $registry = [];
11
12
    /**
13
     * PrefixRegistry constructor.
14
     * @param array $registry
15
     */
16 21
    public function __construct(array $registry)
17
    {
18 21
        foreach ($registry as $scriptType => $prefixes) {
19 21
            if (count($prefixes) !== 2) {
20
                throw new \InvalidArgumentException("Expecting two BIP32 prefixes");
21
            }
22 21
            if (strlen($prefixes[0]) !== 8 || !ctype_xdigit($prefixes[0])) {
23
                throw new \InvalidArgumentException("Invalid private prefix");
24
            }
25 21
            if (strlen($prefixes[1]) !== 8 || !ctype_xdigit($prefixes[1])) {
26 21
                throw new \InvalidArgumentException("Invalid public .prefix");
27
            }
28
        }
29 21
        $this->registry = $registry;
30 21
    }
31
32
    /**
33
     * @param string $scriptType
34
     * @return array
35
     */
36 21
    public function getPrefixes($scriptType)
37
    {
38 21
        if (!array_key_exists($scriptType, $this->registry)) {
39
            throw new \InvalidArgumentException("Unknown script type");
40
        }
41 21
        return $this->registry[$scriptType];
42
    }
43
}
44