Completed
Pull Request — master (#240)
by thomas
73:04
created

TransactionWitnessCollection   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 8
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 51
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A __clone() 0 9 2
A current() 0 4 1
A offsetGet() 0 8 2
1
<?php
2
3
namespace BitWasp\Bitcoin\Collection\Transaction;
4
5
use BitWasp\Bitcoin\Collection\StaticCollection;
6
use BitWasp\Bitcoin\Script\ScriptWitnessInterface;
7
8
class TransactionWitnessCollection extends StaticCollection
9
{
10
    /**
11
     * Initialize a new collection with a list of Inputs.
12
     *
13
     * @param ScriptWitnessInterface[] $vScriptWitness
14
     */
15
    public function __construct(array $vScriptWitness = [])
16
    {
17
        $this->set = new \SplFixedArray(count($vScriptWitness));
18
19
        foreach ($vScriptWitness as $idx => $input) {
20
            if (!$input instanceof ScriptWitnessInterface) {
21
                throw new \InvalidArgumentException('Must provide ScriptWitnessInterface[] to TransactionWitnessCollection');
22
            }
23
24
            $this->set->offsetSet($idx, $input);
25
        }
26
    }
27
28
    public function __clone()
29
    {
30
        $inputs = $this->set;
31
        $this->set = new \SplFixedArray(count($inputs));
32
33
        foreach ($inputs as $idx => $input) {
34
            $this->set->offsetSet($idx, $input);
35
        }
36
    }
37
38
    /**
39
     * @return ScriptWitnessInterface
40
     */
41
    public function current()
42
    {
43
        return $this->set->current();
44
    }
45
46
    /**
47
     * @param int $offset
48
     * @return ScriptWitnessInterface
49
     */
50
    public function offsetGet($offset)
51
    {
52
        if (!$this->set->offsetExists($offset)) {
53
            throw new \OutOfRangeException('No offset found');
54
        }
55
56
        return $this->set->offsetGet($offset);
57
    }
58
}
59