Completed
Pull Request — master (#446)
by thomas
105:00 queued 101:56
created

ScriptWitness::equals()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4.25

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 4
nop 1
dl 0
loc 15
ccs 6
cts 8
cp 0.75
crap 4.25
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace BitWasp\Bitcoin\Script;
4
5
use BitWasp\Bitcoin\Collection\StaticBufferCollection;
6
use BitWasp\Bitcoin\Serializer\Script\ScriptWitnessSerializer;
7
8
class ScriptWitness extends StaticBufferCollection implements ScriptWitnessInterface
9
{
10
    /**
11
     * @param ScriptWitnessInterface $witness
12
     * @return bool
13
     */
14 50
    public function equals(ScriptWitnessInterface $witness)
15
    {
16 50
        $nStack = count($this);
17 50
        if ($nStack !== count($witness)) {
18
            return false;
19
        }
20
21 50
        for ($i = 0; $i < $nStack; $i++) {
22 22
            if (false === $this->offsetGet($i)->equals($witness->offsetGet($i))) {
23
                return false;
24
            }
25
        }
26
27 50
        return true;
28
    }
29
30
    /**
31
     * @return \BitWasp\Buffertools\BufferInterface
32
     */
33
    public function getBuffer()
34
    {
35
        return (new ScriptWitnessSerializer())->serialize($this);
36
    }
37
}
38