Completed
Pull Request — master (#278)
by thomas
73:26 queued 01:49
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 21
cts 21
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 1344
    public function __construct(array $inputs = [])
16
    {
17 1344
        $this->set = new \SplFixedArray(count($inputs));
18 1344
        foreach ($inputs as $idx => $input) {
19 1110
            if (!$input instanceof TransactionInputInterface) {
20 6
                throw new \InvalidArgumentException('Must provide TransactionInputInterface[] to TransactionInputCollection');
21
            }
22 1104
            $this->set->offsetSet($idx, $input);
23 1338
        }
24 1338
    }
25
26 120
    public function __clone()
27
    {
28 120
        $inputs = $this->set;
29 120
        $this->set = new \SplFixedArray(count($inputs));
30
31 120
        foreach ($inputs as $idx => $input) {
32 102
            $this->set->offsetSet($idx, $input);
33 120
        }
34 120
    }
35
36
    /**
37
     * @return TransactionInputInterface[]
38
     */
39
    public function all()
40 72
    {
41
        return $this->set->toArray();
42 72
    }
43
44
    /**
45
     * @return TransactionInputInterface
46
     */
47
    public function current()
48
    {
49 816
        return $this->set->current();
50
    }
51 816
52 12
    /**
53
     * @param int $offset
54
     * @return TransactionInputInterface
55 804
     */
56
    public function offsetGet($offset)
57
    {
58
        if (!$this->set->offsetExists($offset)) {
59
            throw new \OutOfRangeException('No offset found');
60
        }
61
62
        return $this->set->offsetGet($offset);
63
    }
64
}
65