Completed
Pull Request — master (#239)
by thomas
31:39 queued 14:06
created

TransactionWitnessCollection::offsetGet()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
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 1914
    public function __construct(array $vScriptWitness = [])
16
    {
17 1914
        $this->set = new \SplFixedArray(count($vScriptWitness));
18
19 1914
        foreach ($vScriptWitness as $idx => $input) {
20 54
            if (!$input instanceof ScriptWitnessInterface) {
21
                throw new \InvalidArgumentException('Must provide ScriptWitnessInterface[] to TransactionWitnessCollection');
22
            }
23
24 54
            $this->set->offsetSet($idx, $input);
25 1914
        }
26 1914
    }
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 54
    public function current()
42
    {
43 54
        return $this->set->current();
44
    }
45
46
    /**
47
     * @param int $offset
48
     * @return ScriptWitnessInterface
49
     */
50 54
    public function offsetGet($offset)
51
    {
52 54
        if (!$this->set->offsetExists($offset)) {
53
            throw new \OutOfRangeException('No offset found');
54
        }
55
56 54
        return $this->set->offsetGet($offset);
57
    }
58
}
59