ScriptWitness   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 28
ccs 6
cts 10
cp 0.6
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A equals() 0 14 4
A getBuffer() 0 3 1
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