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

TransactionOutputCollection::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
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\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 1320
    public function __construct(array $outputs = [])
17
    {
18 1320
        $this->set = new \SplFixedArray(count($outputs));
19 1320
        foreach ($outputs as $idx => $output) {
20 420
            if (!$output instanceof TransactionOutputInterface) {
21 6
                throw new \InvalidArgumentException('Must provide TransactionOutputInterface[] to TransactionOutputCollection');
22
            }
23 414
            $this->set->offsetSet($idx, $output);
24 1314
        }
25 1314
    }
26
27 120
    public function __clone()
28
    {
29 120
        $outputs = $this->set;
30 120
        $this->set = new \SplFixedArray(count($outputs));
31
32 120
        foreach ($outputs as $idx => $output) {
33 84
            $this->set->offsetSet($idx, $output);
34 120
        }
35 120
    }
36
37
    /**
38
     * @return TransactionOutputInterface[]
39
     */
40 108
    public function all()
41
    {
42 108
        return $this->set->toArray();
43
    }
44
45
    /**
46
     * @return TransactionOutputInterface
47
     */
48
    public function current()
49 120
    {
50
        return $this->set->current();
51 120
    }
52 12
53
    /**
54
     * @param int $offset
55 108
     * @return TransactionOutputInterface
56
     */
57
    public function offsetGet($offset)
58
    {
59
        if (!$this->set->offsetExists($offset)) {
60
            throw new \OutOfRangeException('No offset found');
61
        }
62
63
        return $this->set->offsetGet($offset);
64
    }
65
}
66