Completed
Pull Request — master (#222)
by thomas
24:34
created

TransactionOutputCollection   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 8
c 2
b 1
f 0
lcom 1
cbo 1
dl 0
loc 50
ccs 21
cts 21
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetGet() 0 8 2
A __clone() 0 9 2
A __construct() 0 10 3
A current() 0 4 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 1242
    public function __construct(array $outputs = [])
17
    {
18 1242
        $this->set = new \SplFixedArray(count($outputs));
19 1242
        foreach ($outputs as $idx => $output) {
20 405
            if (!$output instanceof TransactionOutputInterface) {
21 6
                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 171
    public function offsetGet($offset)
50
    {
51 171
        if (!$this->set->offsetExists($offset)) {
52 12
            throw new \OutOfRangeException('No offset found');
53
        }
54
55 159
        return $this->set->offsetGet($offset);
56
    }
57
}
58