Completed
Pull Request — master (#524)
by thomas
40:24 queued 38:13
created

functions.php ➔ decodeOpN()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 5

Importance

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