Completed
Push — master ( 883b2a...6b2c83 )
by thomas
44:21 queued 41:03
created

TransactionInputCollection   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 9
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 57
ccs 23
cts 23
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
A __clone() 0 9 2
A all() 0 4 1
A current() 0 4 1
A offsetGet() 0 8 2
1
<?php
2
3
namespace BitWasp\Bitcoin\Collection\Transaction;
4
5
use BitWasp\Bitcoin\Collection\StaticCollection;
6
use BitWasp\Bitcoin\Transaction\TransactionInputInterface;
7
8
class TransactionInputCollection extends StaticCollection
9
{
10
    /**
11
     * Initialize a new collection with a list of Inputs.
12
     *
13
     * @param TransactionInputInterface[] $inputs
14
     */
15 1350
    public function __construct(array $inputs = [])
16
    {
17 1350
        $this->set = new \SplFixedArray(count($inputs));
18 1350
        foreach ($inputs as $idx => $input) {
19 1116
            if (!$input instanceof TransactionInputInterface) {
20 6
                throw new \InvalidArgumentException('Must provide TransactionInputInterface[] to TransactionInputCollection');
21
            }
22 1110
            $this->set->offsetSet($idx, $input);
23 1344
        }
24 1344
    }
25
26 126
    public function __clone()
27
    {
28 126
        $inputs = $this->set;
29 126
        $this->set = new \SplFixedArray(count($inputs));
30
31 126
        foreach ($inputs as $idx => $input) {
32 108
            $this->set->offsetSet($idx, $input);
33 126
        }
34 126
    }
35
36
    /**
37
     * @return TransactionInputInterface[]
38
     */
39 330
    public function all()
40
    {
41 330
        return $this->set->toArray();
42
    }
43
44
    /**
45
     * @return TransactionInputInterface
46
     */
47 72
    public function current()
48
    {
49 72
        return $this->set->current();
50
    }
51
52
    /**
53
     * @param int $offset
54
     * @return TransactionInputInterface
55
     */
56 822
    public function offsetGet($offset)
57
    {
58 822
        if (!$this->set->offsetExists($offset)) {
59 12
            throw new \OutOfRangeException('No offset found');
60
        }
61
62 810
        return $this->set->offsetGet($offset);
63
    }
64
}
65