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

TransactionWitnessCollection   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 57.14%

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 21
cp 0.5714
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 1272
     */
16
    public function __construct(array $vScriptWitness = [])
17 1272
    {
18
        $this->set = new \SplFixedArray(count($vScriptWitness));
19 1272
20 84
        foreach ($vScriptWitness as $idx => $input) {
21
            if (!$input instanceof ScriptWitnessInterface) {
22
                throw new \InvalidArgumentException('Must provide ScriptWitnessInterface[] to TransactionWitnessCollection');
23
            }
24 84
25 1272
            $this->set->offsetSet($idx, $input);
26 1272
        }
27
    }
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 54
     */
42
    public function all()
43 54
    {
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 54
     * @param int $offset
57
     * @return ScriptWitnessInterface
58
     */
59
    public function offsetGet($offset)
60
    {
61
        if (!$this->set->offsetExists($offset)) {
62
            throw new \OutOfRangeException('No offset found');
63
        }
64
65
        return $this->set->offsetGet($offset);
66
    }
67
}
68