ScriptWitness::equals()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4.25

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 4
nop 1
dl 0
loc 14
ccs 6
cts 8
cp 0.75
crap 4.25
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