WitnessCollectionMutator::null()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Bitcoin\Transaction\Mutator;
6
7
use BitWasp\Bitcoin\Script\ScriptWitnessInterface;
8
9
class WitnessCollectionMutator extends AbstractCollectionMutator
10
{
11
12
    /**
13
     * @param ScriptWitnessInterface[] $inputs
14
     */
15
    public function __construct(array $inputs)
16
    {
17
        /** @var InputMutator[] $set */
18
        $set = [];
19
        foreach ($inputs as $i => $input) {
20
            $set[$i] = new InputMutator($input);
0 ignored issues
show
Bug introduced by
$input of type BitWasp\Bitcoin\Script\ScriptWitnessInterface is incompatible with the type BitWasp\Bitcoin\Transact...ansactionInputInterface expected by parameter $input of BitWasp\Bitcoin\Transact...tMutator::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

20
            $set[$i] = new InputMutator(/** @scrutinizer ignore-type */ $input);
Loading history...
21
        }
22
23
        $this->set = \SplFixedArray::fromArray($set, false);
24
    }
25
26
    /**
27
     * @return InputMutator
28
     */
29
    public function current()
30
    {
31
        return $this->set->current();
32
    }
33
34
    /**
35
     * @param int $offset
36
     * @return InputMutator
37
     */
38
    public function offsetGet($offset): InputMutator
39
    {
40
        if (!$this->set->offsetExists($offset)) {
41
            throw new \OutOfRangeException('Input does not exist');
42
        }
43
44
        return $this->set->offsetGet($offset);
45
    }
46
47
    /**
48
     * @return ScriptWitnessInterface[]
49
     */
50
    public function done(): array
51
    {
52
        $set = [];
53
        foreach ($this->set as $mutator) {
54
            $set[] = $mutator->done();
55
        }
56
57
        return $set;
58
    }
59
60
    /**
61
     * @param int $start
62
     * @param int $length
63
     * @return $this
64
     */
65
    public function slice(int $start, int $length)
66
    {
67
        $end = $this->set->getSize();
68
        if ($start > $end || $length > $end) {
69
            throw new \RuntimeException('Invalid start or length');
70
        }
71
72
        $this->set = \SplFixedArray::fromArray(array_slice($this->set->toArray(), $start, $length), false);
73
        return $this;
74
    }
75
76
    /**
77
     * @return $this
78
     */
79
    public function null()
80
    {
81
        $this->slice(0, 0);
82
        return $this;
83
    }
84
85
    /**
86
     * @param ScriptWitnessInterface $witness
87
     * @return $this
88
     */
89
    public function add(ScriptWitnessInterface $witness)
90
    {
91
        $size = $this->set->getSize();
92
        $this->set->setSize($size + 1);
93
94
        $this->set[$size] = new InputMutator($witness);
0 ignored issues
show
Bug introduced by
$witness of type BitWasp\Bitcoin\Script\ScriptWitnessInterface is incompatible with the type BitWasp\Bitcoin\Transact...ansactionInputInterface expected by parameter $input of BitWasp\Bitcoin\Transact...tMutator::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

94
        $this->set[$size] = new InputMutator(/** @scrutinizer ignore-type */ $witness);
Loading history...
95
        return $this;
96
    }
97
98
    /**
99
     * @param int $i
100
     * @param ScriptWitnessInterface $input
101
     * @return $this
102
     */
103
    public function set(int $i, ScriptWitnessInterface $input)
104
    {
105
        $this->set[$i] = new InputMutator($input);
0 ignored issues
show
Bug introduced by
$input of type BitWasp\Bitcoin\Script\ScriptWitnessInterface is incompatible with the type BitWasp\Bitcoin\Transact...ansactionInputInterface expected by parameter $input of BitWasp\Bitcoin\Transact...tMutator::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

105
        $this->set[$i] = new InputMutator(/** @scrutinizer ignore-type */ $input);
Loading history...
106
        return $this;
107
    }
108
}
109