Completed
Pull Request — master (#244)
by thomas
201:55 queued 131:14
created

TransactionInputWitness   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 53
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A getScript() 0 4 1
A getStack() 0 4 1
A isNull() 0 4 1
1
<?php
2
3
namespace BitWasp\Bitcoin\Transaction;
4
5
use BitWasp\Bitcoin\Script\Parser\Operation;
6
use BitWasp\Bitcoin\Script\ScriptInterface;
7
use BitWasp\Buffertools\BufferInterface;
8
9
class TransactionInputWitness implements TransactionInputWitnessInterface
10
{
11
    /**
12
     * @var BufferInterface[]
13
     */
14
    private $values = [];
15
16
    /**
17
     * @var ScriptInterface
18
     */
19
    private $script;
20
21
    /**
22
     * TransactionInputWitness constructor.
23
     * @param ScriptInterface $script
24
     */
25
    public function __construct(ScriptInterface $script)
26
    {
27
        array_map(function (Operation $value) {
28
            if (!$value->isPush()) {
29
                throw new \InvalidArgumentException('Script must only contain push ops');
30
            }
31
32
            $this->values[] = $value->getData();
33
        }, $script->getScriptParser()->decode());
34
35
        $this->script = $script;
36
    }
37
38
    /**
39
     * @return ScriptInterface
40
     */
41
    public function getScript()
42
    {
43
        return $this->script;
44
    }
45
46
    /**
47
     * @return BufferInterface[]
48
     */
49
    public function getStack()
50
    {
51
        return $this->values;
52
    }
53
54
    /**
55
     * @return bool
56
     */
57
    public function isNull()
58
    {
59
        return count($this->values) === 0;
60
    }
61
}
62