Completed
Pull Request — master (#278)
by thomas
73:26 queued 01:49
created

TransactionWitnessCollection::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 1
cts 1
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace BitWasp\Bitcoin\Collection\Transaction;
4
5
use BitWasp\Bitcoin\Collection\StaticCollection;
6
use BitWasp\Bitcoin\Script\ScriptInterface;
7
use BitWasp\Bitcoin\Script\ScriptWitnessInterface;
8
9
class TransactionWitnessCollection extends StaticCollection
10
{
11
    /**
12
     * Initialize a new collection with a list of Inputs.
13
     *
14
     * @param ScriptWitnessInterface[] $vScriptWitness
15 1272
     */
16
    public function __construct(array $vScriptWitness = [])
17 1272
    {
18
        $this->set = new \SplFixedArray(count($vScriptWitness));
19 1272
20 84
        foreach ($vScriptWitness as $idx => $input) {
21
            if (!$input instanceof ScriptWitnessInterface) {
22
                throw new \InvalidArgumentException('Must provide ScriptWitnessInterface[] to TransactionWitnessCollection');
23
            }
24 84
25 1272
            $this->set->offsetSet($idx, $input);
26 1272
        }
27
    }
28
29
    public function __clone()
30
    {
31
        $inputs = $this->set;
32
        $this->set = new \SplFixedArray(count($inputs));
33
34
        foreach ($inputs as $idx => $input) {
35
            $this->set->offsetSet($idx, $input);
36
        }
37
    }
38
39
    /**
40
     * @return ScriptWitnessInterface[]
41 54
     */
42
    public function all()
43 54
    {
44
        return $this->set->toArray();
45
    }
46
47
    /**
48
     * @return ScriptWitnessInterface
49
     */
50 54
    public function current()
51
    {
52 54
        return $this->set->current();
53
    }
54
55
    /**
56 54
     * @param int $offset
57
     * @return ScriptWitnessInterface
58
     */
59
    public function offsetGet($offset)
60
    {
61
        if (!$this->set->offsetExists($offset)) {
62
            throw new \OutOfRangeException('No offset found');
63
        }
64
65
        return $this->set->offsetGet($offset);
66
    }
67
}
68