Completed
Pull Request — master (#525)
by thomas
26:53
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 1636
    if ($op === Opcodes::OP_0) {
8 172
        return 0;
9
    }
10
11 1514
    if (!($op === Opcodes::OP_1NEGATE || $op >= Opcodes::OP_1 && $op <= Opcodes::OP_16)) {
12 90
        throw new \RuntimeException("Invalid opcode");
13
    }
14
15 1476
    return (int) $op - (Opcodes::OP_1 - 1);
16
}
17
18
function encodeOpN($op)
19
{
20 80
    if ($op === 0) {
21 26
        return Opcodes::OP_0;
22
    }
23
24 56
    if (!($op === -1 || $op >= 1 && $op <= 16)) {
25
        throw new \RuntimeException("Invalid value");
26
    }
27
28 56
    return (int) Opcodes::OP_1 + $op - 1;
29
}
30