Completed
Push — master ( fceb66...595279 )
by thomas
73:29 queued 71:27
created

Operation   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
dl 0
loc 84
ccs 18
cts 20
cp 0.9
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A isPush() 0 4 1
A getOp() 0 4 1
A getData() 0 4 1
A getDataSize() 0 8 2
A encode() 0 8 2
1
<?php
2
3
namespace BitWasp\Bitcoin\Script\Parser;
4
5
use BitWasp\Bitcoin\Script\Opcodes;
6
use BitWasp\Buffertools\BufferInterface;
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 BufferInterface
22
     */
23
    private $pushData;
24
25
    /**
26
     * @var int
27
     */
28
    private $pushDataSize;
29
30
    /**
31
     * Operation constructor.
32
     * @param int $opCode
33
     * @param BufferInterface $pushData
34
     * @param int $pushDataSize
35
     */
36 2594
    public function __construct($opCode, BufferInterface $pushData, $pushDataSize = 0)
37
    {
38 2594
        $this->push = $opCode >= 0 && $opCode <= Opcodes::OP_PUSHDATA4;
39 2594
        $this->opCode = $opCode;
40 2594
        $this->pushData = $pushData;
41 2594
        $this->pushDataSize = $pushDataSize;
42 2594
    }
43
44
    /**
45
     * @return bool
46
     */
47 2556
    public function isPush()
48
    {
49 2556
        return $this->push;
50
    }
51
52
    /**
53
     * @return int
54
     */
55 2574
    public function getOp()
56
    {
57 2574
        return $this->opCode;
58
    }
59
60
    /**
61
     * @return BufferInterface
62
     */
63 2560
    public function getData()
64
    {
65 2560
        return $this->pushData;
66
    }
67
68
    /**
69
     * @return int
70
     */
71 1932
    public function getDataSize()
72
    {
73 1932
        if (!$this->push) {
74
            throw new \RuntimeException("Op wasn't a push operation");
75
        }
76
77 1932
        return $this->pushDataSize;
78
    }
79
80
    /**
81
     * @return BufferInterface|int
82
     */
83 2
    public function encode()
84
    {
85 2
        if ($this->push) {
86 2
            return $this->pushData;
87
        } else {
88
            return $this->opCode;
89
        }
90
    }
91
}
92