Completed
Push — master ( 883b2a...6b2c83 )
by thomas
44:21 queued 41:03
created

TransactionWitnessCollection::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 12
ccs 7
cts 8
cp 0.875
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
crap 3.0175
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
     */
16 1278
    public function __construct(array $vScriptWitness = [])
17
    {
18 1278
        $this->set = new \SplFixedArray(count($vScriptWitness));
19
20 1278
        foreach ($vScriptWitness as $idx => $input) {
21 84
            if (!$input instanceof ScriptWitnessInterface) {
22
                throw new \InvalidArgumentException('Must provide ScriptWitnessInterface[] to TransactionWitnessCollection');
23
            }
24
25 84
            $this->set->offsetSet($idx, $input);
26 1278
        }
27 1278
    }
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
     */
42
    public function all()
43
    {
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
     * @param int $offset
57
     * @return ScriptWitnessInterface
58
     */
59 54
    public function offsetGet($offset)
60
    {
61 54
        if (!$this->set->offsetExists($offset)) {
62
            throw new \OutOfRangeException('No offset found');
63
        }
64
65 54
        return $this->set->offsetGet($offset);
66
    }
67
}
68