ScriptWitness::getBuffer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
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\Script;
6
7
use BitWasp\Bitcoin\Collection\StaticBufferCollection;
8
use BitWasp\Bitcoin\Serializer\Script\ScriptWitnessSerializer;
9
use BitWasp\Buffertools\BufferInterface;
10
11
class ScriptWitness extends StaticBufferCollection implements ScriptWitnessInterface
0 ignored issues
show
Deprecated Code introduced by
The class BitWasp\Bitcoin\Collection\StaticBufferCollection has been deprecated: v2.0.0 ( Ignorable by Annotation )

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

11
class ScriptWitness extends /** @scrutinizer ignore-deprecated */ StaticBufferCollection implements ScriptWitnessInterface
Loading history...
12
{
13
    /**
14
     * @param ScriptWitnessInterface $witness
15
     * @return bool
16
     */
17 50
    public function equals(ScriptWitnessInterface $witness): bool
18
    {
19 50
        $nStack = count($this);
20 50
        if ($nStack !== count($witness)) {
21
            return false;
22
        }
23
24 50
        for ($i = 0; $i < $nStack; $i++) {
25 22
            if (false === $this->offsetGet($i)->equals($witness->offsetGet($i))) {
26
                return false;
27
            }
28
        }
29
30 50
        return true;
31
    }
32
33
    /**
34
     * @return \BitWasp\Buffertools\BufferInterface
35
     */
36
    public function getBuffer(): BufferInterface
37
    {
38
        return (new ScriptWitnessSerializer())->serialize($this);
39
    }
40
}
41