Completed
Push — master ( 319c7a...cdee94 )
by thomas
79:06 queued 75:43
created

Operation::getOp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace BitWasp\Bitcoin\Script\Parser;
4
5
use BitWasp\Bitcoin\Script\Opcodes;
6
use BitWasp\Buffertools\Buffer;
7
8
class Operation
9
{
10
    /**
11
     * @var bool
12
     */
13
    private $push;
14
15
    /**
16
     * @var int
17
     */
18
    private $opCode;
19
20
    /**
21
     * @var Buffer
22
     */
23
    private $pushData;
24
25
    /**
26
     * @var int
27
     */
28
    private $pushDataSize;
29
30
    /**
31
     * Operation constructor.
32
     * @param int $opCode
33
     * @param Buffer $pushData
34
     * @param int $pushDataSize
35
     */
36 1041
    public function __construct($opCode, Buffer $pushData, $pushDataSize = 0)
37
    {
38 1041
        $this->push = $opCode >= 0 && $opCode <= Opcodes::OP_PUSHDATA4;
39 1041
        $this->opCode = $opCode;
40 1041
        $this->pushData = $pushData;
41 1041
        $this->pushDataSize = $pushDataSize;
42 1041
    }
43
44
    /**
45
     * @return bool
46
     */
47 975
    public function isPush()
48
    {
49 975
        return $this->push;
50
    }
51
52
    /**
53
     * @return int
54
     */
55 969
    public function getOp()
56
    {
57 969
        return $this->opCode;
58
    }
59
60
    /**
61
     * @return Buffer
62
     */
63 963
    public function getData()
64
    {
65 963
        return $this->pushData;
66
    }
67
68
    /**
69
     * @return int
70
     */
71 633
    public function getDataSize()
72
    {
73 633
        if (!$this->push) {
74
            throw new \RuntimeException("Op wasn't a push operation");
75
        }
76
77 633
        return $this->pushDataSize;
78
    }
79
}
80