Completed
Pull Request — master (#403)
by thomas
73:13 queued 70:38
created

ScriptWitness::getBuffer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
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 84
    public function equals(ScriptWitnessInterface $witness)
15
    {
16 84
        $nStack = count($this);
17 84
        if ($nStack !== count($witness)) {
18
            return false;
19
        }
20
21 84
        for ($i = 0; $i < $nStack; $i++) {
22 48
            if (false === $this->offsetGet($i)->equals($witness->offsetGet($i))) {
23
                return false;
24
            }
25 16
        }
26
27 84
        return true;
28
    }
29
30
    /**
31
     * @return \BitWasp\Buffertools\BufferInterface
32
     */
33 102
    public function getBuffer()
34
    {
35 102
        return (new ScriptWitnessSerializer())->serialize($this);
36
    }
37
}
38