Completed
Push — master ( eabe8c...61f277 )
by thomas
25:26
created

decodeOpN()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 5
nc 3
nop 1
dl 0
loc 11
ccs 5
cts 5
cp 1
crap 5
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Bitcoin\Script;
6
7
function decodeOpN(int $op): int
8
{
9 3151
    if ($op === Opcodes::OP_0) {
10 286
        return 0;
11
    }
12
13 2929
    if (!($op === Opcodes::OP_1NEGATE || $op >= Opcodes::OP_1 && $op <= Opcodes::OP_16)) {
14 69
        throw new \RuntimeException("Invalid opcode");
15
    }
16
17 2887
    return (int) $op - (Opcodes::OP_1 - 1);
18
}
19
20
function encodeOpN(int $op): int
21
{
22 73
    if ($op === 0) {
23 37
        return Opcodes::OP_0;
24
    }
25
26 49
    if (!($op === -1 || $op >= 1 && $op <= 16)) {
27
        throw new \RuntimeException("Invalid value");
28
    }
29
30 49
    return (int) Opcodes::OP_1 + $op - 1;
31
}
32