Completed
Push — master ( c7419f...b9ebc8 )
by thomas
35:04 queued 31:19
created

TransactionOutputCollection::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0176

Importance

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