Completed
Push — master ( 1c8af5...5745ff )
by thomas
04:13 queued 02:50
created

Util::witnessProgram()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.2
c 0
b 0
f 0
cc 4
eloc 5
nc 1
nop 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: tk
5
 * Date: 9/25/17
6
 * Time: 2:20 PM
7
 */
8
9
namespace BitWasp\Test\Bech32;
10
11
12
class Util
13
{
14
    public static function witnessProgram($version, $program)
15
    {
16
        if ($version < 0 || $version > 16) {
17
            throw new \RuntimeException("Invalid version for witness program");
18
        }
19
20
        $version = pack("C", ($version > 0 ? (0x50 + $version) : 0));
21
        $length = pack("C", strlen($program));
22
23
        return unpack("H*", "{$version}{$length}{$program}")[1];
24
    }
25
}
26