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

TransactionWitnessCollection::offsetGet()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace BitWasp\Bitcoin\Collection\Transaction;
4
5
use BitWasp\Bitcoin\Collection\StaticCollection;
6
use BitWasp\Bitcoin\Transaction\TransactionInputWitnessInterface;
7
8
class TransactionWitnessCollection extends StaticCollection
9
{
10
    /**
11
     * Initialize a new collection with a list of Inputs.
12
     *
13
     * @param TransactionInputWitnessInterface[] $inputs
14
     */
15
    public function __construct(array $inputs = [])
16
    {
17
        $this->set = new \SplFixedArray(count($inputs));
18
19
        foreach ($inputs as $idx => $input) {
20
            if (!$input instanceof TransactionInputWitnessInterface) {
21
                throw new \InvalidArgumentException('Must provide TransactionInputWitnessInterface[] 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 TransactionInputWitnessInterface
40
     */
41
    public function current()
42
    {
43
        return $this->set->current();
44
    }
45
46
    /**
47
     * @param int $offset
48
     * @return TransactionInputWitnessInterface
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