Completed
Pull Request — master (#199)
by thomas
21:24 queued 35s
created

Operation   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 93.75%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 72
wmc 7
lcom 1
cbo 0
ccs 15
cts 16
cp 0.9375
rs 10

5 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
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