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

TransactionWitnessCollection   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 52.17%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 9
c 3
b 0
f 2
lcom 1
cbo 1
dl 0
loc 59
ccs 12
cts 23
cp 0.5217
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 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\Script\ScriptInterface;
7
use BitWasp\Bitcoin\Script\ScriptWitnessInterface;
8
9
class TransactionWitnessCollection extends StaticCollection
10
{
11
    /**
12
     * Initialize a new collection with a list of Inputs.
13
     *
14
     * @param ScriptWitnessInterface[] $vScriptWitness
15
     */
16 1278
    public function __construct(array $vScriptWitness = [])
17
    {
18 1278
        $this->set = new \SplFixedArray(count($vScriptWitness));
19
20 1278
        foreach ($vScriptWitness as $idx => $input) {
21 84
            if (!$input instanceof ScriptWitnessInterface) {
22
                throw new \InvalidArgumentException('Must provide ScriptWitnessInterface[] to TransactionWitnessCollection');
23
            }
24
25 84
            $this->set->offsetSet($idx, $input);
26 1278
        }
27 1278
    }
28
29
    public function __clone()
30
    {
31
        $inputs = $this->set;
32
        $this->set = new \SplFixedArray(count($inputs));
33
34
        foreach ($inputs as $idx => $input) {
35
            $this->set->offsetSet($idx, $input);
36
        }
37
    }
38
39
    /**
40
     * @return ScriptWitnessInterface[]
41
     */
42
    public function all()
43
    {
44
        return $this->set->toArray();
45
    }
46
47
    /**
48
     * @return ScriptWitnessInterface
49
     */
50 54
    public function current()
51
    {
52 54
        return $this->set->current();
53
    }
54
55
    /**
56
     * @param int $offset
57
     * @return ScriptWitnessInterface
58
     */
59 54
    public function offsetGet($offset)
60
    {
61 54
        if (!$this->set->offsetExists($offset)) {
62
            throw new \OutOfRangeException('No offset found');
63
        }
64
65 54
        return $this->set->offsetGet($offset);
66
    }
67
}
68